Q L*_*ker 6 android textview compound-drawables
我想事先知道视图的大小。我是这样测量它的大小的。
public static int[] measureSize(ViewGroup parent, int layoutId)
{
View view = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
view.measure(spec, spec);
final int width = view.getMeasuredWidth(); // ? 0, not include compound drawable size and relative padding. WHY
final int height = view.getMeasuredHeight();
return new int[]{width, height};
}
Run Code Online (Sandbox Code Playgroud)
这是布局文件:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="?android:listChoiceIndicatorSingle"
android:drawablePadding="20dp"/>
Run Code Online (Sandbox Code Playgroud)
问题:测量的视图宽度始终不包括复合可绘制尺寸及其相关的填充。如果我不设置文本,则测量的宽度始终为0。如果设置非空值,则宽度仅适用于文本。为什么?我怎样才能得到正确的尺寸?
提前致谢。
| 归档时间: |
|
| 查看次数: |
399 次 |
| 最近记录: |