java - 如何获取 compundDrawable 的运行时宽度和高度
问题描述
我想知道 CompoundDrawble 的运行时宽度和高度。
我曾尝试使用布局检查器,但它显示了文本框 + 可绘制的高度。
ViewObserverTree 无助于将 frawble 和文本分开以仅获得可绘制高度。
我也试过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();
试试这个代码
推荐阅读
- firebase - 使用 Firebase Crashlytics 获取发生崩溃的用户的 ID
- c++ - 如何递归地将十六进制转换为十进制
- python - 如何摆脱相互更新小部件的循环?
- python - Selenium-Python:无法清除 chrome 浏览器缓存
- linux - 如何存储已经通过管道的命令的输出
- python - 如何在python中编写多个json文件?
- docker - 在 docker-compose 驱动程序选择中设置 Docker 卷大小配额?
- mysql - 2 在查询中选择 ORDER BY
- python - 创建读取 CSV 文件的函数
- c++ - 是什么让 boost::shared_mutex 这么慢