viewpager
我的布局中有一个:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"></ListView>
<CustomViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
现在,我想获取的实际宽度和高度ViewPager
:
public class CustomViewPager extends ViewPager {
public MyBookView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d("pager","width:" + getWidth() + "mwidth:" + getMeasuredWidth());
}
}
而width
和mwidth
始终是0
。
有什么问题?
在onMeasure()
调用之后,您需要等待获取宽度和高度。该视图尚未经历其布局生命周期。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句