Adarsh Adarsh - 1 year ago 72
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.

Answer Source
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..

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download