Adarsh Adarsh - 1 month ago 6x
Android Question

set width and height of a drawable object in runtime process in android

Hi I have a

object in which content is loaded at
process.I want to get its actual width and height so I used this code :

int x=drawable.getIntrinsicWidth();
int y=drawable.getIntrinsicHeight();

Ans the result is x as 72 and y as 72.Now I want to set my
object width and height as 72.How can I do that.Is there any solution.

Drawable drawable = getResources().getDrawable(R.drawable.yourAwesomeDrawable);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
// Scale it to 100 x 100
Drawable newDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 100, 100, true));

You could also try setBounds(), but I am not quite sure..