36 lines
1.0 KiB
Plaintext
36 lines
1.0 KiB
Plaintext
|
package com.novelbook.android.utils;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.support.annotation.NonNull;
|
||
|
import android.support.annotation.Nullable;
|
||
|
import android.support.v4.view.ViewPager;
|
||
|
import android.util.AttributeSet;
|
||
|
import android.view.View;
|
||
|
|
||
|
public class MyViewPager extends ViewPager {
|
||
|
public MyViewPager(Context context) {
|
||
|
super(context);
|
||
|
}
|
||
|
|
||
|
public MyViewPager(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);
|
||
|
}
|
||
|
}
|