自定义ViewPager,重写ViewPager中的onMeasure方法:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
ViewGroup.LayoutParams params = child.getLayoutParams();
child.measure(widthMeasureSpec,getChildMeasureSpec(heightMeasureSpec,0,params.height));
int h = child.getMeasuredHeight();
if (h>height)height=h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}