package com.mylhyl.circledialog.view;
|
|
import android.content.Context;
|
import android.view.View;
|
|
import androidx.annotation.NonNull;
|
import androidx.viewpager.widget.ViewPager;
|
|
/**
|
* Created by hupei on 2019/1/16 10:42.
|
*/
|
class WrapViewPage extends ViewPager {
|
|
public WrapViewPage(@NonNull Context context) {
|
super(context);
|
}
|
|
@Override
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
int height = 0;
|
//下面遍历所有child的高度
|
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) //采用最大的view的高度。
|
height = h;
|
}
|
if (height > 0) {
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
|
}
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
}
|
}
|