解决 viewpager 不能使用wrap_content 属性

public class MyViewPager extends ViewPager {


public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}


public MyViewPager(Context context) {
super(context);
}
 @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);  
   }  
 
 
  

}


转自  http://hzd.iteye.com/blog/2079141

你可能感兴趣的:(android)