码迷,mamicode.com
首页 > 其他好文 > 详细

方形布局SquareLayout

时间:2016-01-08 11:39:39      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

 1 public class SquareLayout extends RelativeLayout {
 2     public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
 3         super(context, attrs, defStyle);
 4     }
 5 
 6     public SquareLayout(Context context, AttributeSet attrs) {
 7         super(context, attrs);
 8     }
 9 
10     public SquareLayout(Context context) {
11         super(context);
12     }
13 
14     @Override
15     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
16         setMeasuredDimension(getDefaultSize(0, widthMeasureSpec),
17                 getDefaultSize(0, heightMeasureSpec));
18         int childWidthSize = getMeasuredWidth();
19         int childHeightSize = getMeasuredHeight();
20         // 高度和宽度一样
21         heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(
22                 childWidthSize, MeasureSpec.EXACTLY);
23         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
24     }
25 }

 

方形布局SquareLayout

标签:

原文地址:http://www.cnblogs.com/lavalike/p/5112618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!