给你个思路吧.
@
Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
double width, height;
height = width = getMeasuredWidth();
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) width, MeasureSpec.EXACTLY);
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) height, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
这个段代码我是用在自定义 LinearLayout 里的.效果是这个 LinearLayout 是一个正方形.边长为原宽度.你自己改改就出来咯,不过我觉得还是 weight 好使..