I am trying to do a blurred background for an activity with linearlayout with a BitmapDrawable. The original and blurred bitmaps are like 100x100. I want to scale this uniformly for the phone resolution ( eg. 1080p which isn't a square). I get the background icon at runtime.
LinearLayout layout = (LinearLayout) findViewById(R.id.mylinearlayout);
Bitmap bmp = imgLoader.getBitmap(iconUrl);
//Blur using this thread http://stackoverflow.com/questions/14780006/transparent-blurry-view-which-blurs-layout-underneath
Bitmap blurredBmp = CommonUtils.blurBitmap(bmp, Constants.RADIUS);
BitmapDrawable bmpdrawable = new BitmapDrawable(getResources(),blurredBmp);
bmpdrawable.setAlpha(Constants.ALPHA);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable(bmpdrawable);
} else {
layout.setBackground(bmpdrawable);
}
Now, the issue : when I set the background, the 100x100 is basically getting stretched to non-square phone resolution and it is looking weird.
What I want : fill the entire activity background with stretched bitmap. It's OK if part of it is clipped but aspect ratio needs to be maintained.
What I tried: lot of threads on setting layout background suggest using imageview as one of the elements + use gravity and fill_parent. I don't want to do this since I have other images to show on the screen.
I tried Bitmap.createScaledBitmap when creating blurred bitmap or sending varied width/height it isn't working. any help will be appreciated.
Just marking this as a dupe of another thread without understanding the issue isn't cool as well.
thanks