public static Drawable insetBitmap(@NonNull Context context, @NonNull Bitmap bitmap) { BitmapDrawable bitmapDrawable = new BitmapDrawable(context.getResources(), bitmap); bitmapDrawable.setBounds(0, 0, bitmapDrawable.getIntrinsicWidth(), bitmapDrawable.getIntrinsicHeight()); int inset = (DisplayUtils.getScreenWidth(context) - bitmapDrawable.getBounds().right) / 2; if (inset <= 0) { return bitmapDrawable; } InsetDrawable insetDrawable = new InsetDrawable(bitmapDrawable, inset, 0, inset, 0); insetDrawable.setBounds(0, 0, DisplayUtils.getScreenWidth(context), bitmapDrawable.getIntrinsicHeight()); return insetDrawable; } }