I had a background image, it was not large, but with strange sizes - so stretching and poor performance. I made a method with the Context, View and drawable ID (int) parameters, which will correspond to the screen size of the device. Use this, for example, in Fragments onCreateView to set the background.
public void setBackground(Context context, View view, int drawableId){ Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableId); bitmap = Bitmap.createScaledBitmap(bitmap, Resources.getSystem().getDisplayMetrics() .widthPixels, Resources.getSystem().getDisplayMetrics().heightPixels, true); BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bitmap); view.setBackground(bitmapDrawable); }
ZooMagic Mar 21 '17 at 13:15 2017-03-21 13:15
source share