Java tutorial
//package com.java2s; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Build; public class Main { public static Drawable getDrawableByWidthAndHeight(Resources res, int drawId, int width, int height) { Drawable draw = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { draw = res.getDrawable(drawId, null); } else { draw = res.getDrawable(drawId); } draw.setBounds(0, 0, width, height); return draw; } }