码迷,mamicode.com
首页 > 移动开发 > 详细

android measure

时间:2015-04-26 21:05:20      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

几个有用的方法

求一个view的宽度

public static void measureView(View child) {
        ViewGroup.LayoutParams p = child.getLayoutParams();
        if (p == null) {
            p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }

        int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0 + 0, p.width);
        int lpHeight = p.height;
        int childHeightSpec;
        if (lpHeight > 0) {
            childHeightSpec = MeasureSpec.makeMeasureSpec(lpHeight, MeasureSpec.EXACTLY);
        } else {
            childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        }
        child.measure(childWidthSpec, childHeightSpec);
    }

调用过程

ViewUtil.measureView(mHeaderView);
mHeadViewHeight = mHeaderView.getMeasuredHeight();

 

android measure

标签:

原文地址:http://www.cnblogs.com/wjw334/p/4458284.html

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