1 public class ViewMeasuare extends View { 2 3 public ViewMeasuare(Context context, AttributeSet attrs) { 4 super(context, attrs); 5 } 6 7 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 8 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 9 setMeasuredDimension(780, 120); 10 } 11 12 }
setMeasuredDimension 这个方法的确把我实实在在的坑了一把