如何获取 compundDrawable 的运行时宽度和高度



我想知道复合画屎的运行时宽度和高度。

我尝试使用布局检查器,但它显示了文本框 + 可绘制对象的高度。

ViewObserverTree无助于分离碎片和文本 以仅获取可绘制高度。

我也试过drawable.getBounds()

但它会给我编译时间的高度和宽度。

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

drawable.getBounds().

您将如何获取运行时值(以 pd 和 pxl 为单位(

Drawable[] drawables = textView.getCompoundDrawables();
Bitmap myBitmap = ((BitmapDrawable)drawables[1] ).getBitmap();
//Bitmap myBitmap = ((BitmapDrawable )imageView.getDrawable()).getBitmap();
int width = myBitmap .getWidth();
int height = myBitmap .getHeight();

试试这个代码

最新更新