CustomViewPager|CustomViewPager 穷途末路时试试这个
【CustomViewPager|CustomViewPager 穷途末路时试试这个】 这不是原创
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
public class CustomViewPager extends ViewPager {public CustomViewPager(Context context) {
super(context);
}public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}@Override
protected void onMeasure(int widthMeasureSpec, int 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.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
推荐阅读
- 任时光绽放成六月繁花
- 一个人的碎碎念
- 昨夜小楼听风
- 20170612时间和注意力开销记录
- 远去的风筝
- 为什么你的路演总会超时()
- 杜月笙的口才
- 时间老了
- MediaRecorder前后摄像头同时录像
- 眉头开了