先测量好,然后setMeasuredDimension(measuredHeight, measuredWidth);
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
依据specMode的值,(MeasureSpec有3种模式分别是UNSPECIFIED, EXACTLY和AT_MOST)
如果是AT_MOST,specSize 代表的是最大可获得的空间;
如果是EXACTLY,specSize 代表的是精确的尺寸;
如果是UNSPECIFIED,对于控件尺寸来说,没有任何参考意义。
可以在xml中设置layout_width,layout_height,也可以在code中用LayoutParams来控制
自定义view的父类肯定是View或者View的子类。所以也是支持layout_width,layout_height属性的,如果想另外控制的话,可以重写View的onDraw方法。