0

我想知道 CompoundDrawble 的运行时宽度和高度。

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

ViewObserverTree 无助于将 frawble 和文本分开以仅获得可绘制高度。

我也试过drawable.getBounds()

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

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


drawable.getBounds().

您将如何获得运行时值(在 pd 和 pxl 中)

4

1 回答 1

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

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

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

试试这个代码

于 2018-10-15T08:55:41.303 回答