- NestedScrollView嵌套ViewPager出现页面不
- Android NestedScrollView嵌套ViewPa
- 采坑笔记_多NestedScrollview+ViewPage+
- 006 采坑-NestedScrollView嵌套ViewPag
- NestedScrollView嵌套ViewPager
- 踩坑之路:NestedScrollView嵌套ViewPager
- 解决NestedScrollView嵌套viewpager+fr
- android进入页面时焦点不在首页问题
- NestedScrollView嵌套RecyclerView焦点
- NestedScrollView进入界面不能定位到顶部问题解决
模拟b站首页出现NestedScrollView嵌套ViewPager出现页面不显示问题:
结局方案:重写ViewPager的onMeasure方法
/**
* author: wmr
* date: 2016/12/02
* version: 1.0
* description:自适应子View高度的viewPager:ViewPager的onMeasure方法
*/
public classAutoHeightViewPagerextendsViewPager {
publicAutoHeightViewPager(Context context,AttributeSet attrs) {
super(context,attrs);
}
@Override
protected voidonMeasure(intwidthMeasureSpec, intheightMeasureSpec) {
intheight =0;
// 下面遍历所有child的高度
for(inti =0;i < getChildCount();i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec,
MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED));
inth = child.getMeasuredHeight();
// 采用最大的view的高度
if(h > height) {
height = h;
}
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
}
}
网友评论