【发布时间】:2014-11-28 18:28:29
【问题描述】:
假设我们在 XML 中声明了自定义视图,并覆盖了它的 onMeasure() 方法:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Maximal length of line is width of this View
width = this.getLayoutParams().width;
如果设置了 XML 属性 android:layout_width="100px",则 width 返回值 100。但如果属性为 android:layout_width="match_parent" 或 android:layout_width="wrap_content",则返回 -1 或 -2。那么在这种情况下我们如何获得这个 View 的测量宽度呢?
【问题讨论】:
标签: android layout view width onmeasure