how to get runtime width and height of a compundDrawable

24 Views Asked by At

I want to know the runtime width and height of a compoundDrawble.

I have tried to use layout inspector, but it shows the height of the text box + drawable.

ViewObserverTree won't help to separate the frawble and the text to get only the drawable height.

I have also tried drawable.getBounds()

but it will give me the compile time height and width.

Drawable[] compoundDrawablesRelative = TextViewCompat
    .getCompoundDrawablesRelative(targetTextView);


drawable.getBounds().

How would you get the runtime values (in pd and pxl)

1

There are 1 best solutions below

1
Jinson Paul On
  Drawable[] drawables = textView.getCompoundDrawables();
  Bitmap myBitmap = ((BitmapDrawable)drawables[1] ).getBitmap();

  //Bitmap myBitmap = ((BitmapDrawable )imageView.getDrawable()).getBitmap();

    int width = myBitmap .getWidth();
    int height = myBitmap .getHeight();

try this code