@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int viewHeight = 0; View childView = getChildAt(getCurrentItem()); if(childView != null) //有可能没有子view { childView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0,MeasureSpec.UNSPECIFIED)); viewHeight = childView.getMeasuredHeight(); //得到父元素对自身设定的高 heightMeasureSpec = MeasureSpec.makeMeasureSpec(viewHeight, MeasureSpec.EXACTLY); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); }