My splash screen stretches badly when I run my app , so I tried a solution on one of the questions here to manually adjust dither and purge like so
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
myOptions.inDither = false;
myOptions.inPurgeable = true;
Bitmap preparedBitmap = BitmapFactory.decodeResource(getApplication()
.getResources(), R.drawable.bg, myOptions);
Drawable background = new BitmapDrawable(preparedBitmap);
((LinearLayout) findViewById(R.id.layout_main))
.setBackgroundDrawable(background);
Instead of putting the image of the splash which causes bad stretching I am setting the background and configuring options.
My xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout_main">
</LinearLayout>
I tried Clean+rebuild+refresh but still I get a NullPointerException at
((LinearLayout) findViewById(R.id.layout_main))
.setBackgroundDrawable(background);
It cannot find the linear layout. Any ideas? Help!
I solved this by adding some dummy content like imageview with src = @null to the layout. Otherwise the layout did not inflate. After that I did what I was doing and voila. Moral: To inflate a layout that you want to find programmatically – add some dummy content and not just the layout (I dont know what the official docs say, but this is what I ve found in my case)