我有一个带有3个选项卡的View Pager。最初,当打开一个页面时一切都很好,但是当我打开第二个片段并回到第一个片段的高度时,第一个片段的高度更改为第二个片段 在第二个片段中,我显示了recyclerview,在第一个片段中,我显示了常规布局
这是我的自定义视图寻呼机
public class WrapContentHeightViewPager extends ViewPager {
private int mCurrentPagePosition = 0;
public WrapContentHeightViewPager(Context context) {
super(context);
}
public WrapContentHeightViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = 0;
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if (h > height) height = h;
}
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void reMeasureCurrentPage(int position) {
mCurrentPagePosition = position;
requestLayout();
}
}