如何解决在scrollview中的viewpager高度自适应的
时间:2016年3月18日16:47:56
/*** 自动适应高度的ViewPager* @author**/public class CustomViewPager extends ViewPager {public CustomViewPager(Context context) {super(context);}public CustomViewPager(Context context, AttributeSet attrs) {super(context, attrs);}@Overrideprotected 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);}}

浙公网安备 33010602011771号