zoukankan      html  css  js  c++  java
  • android measure

    几个有用的方法

    求一个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();
  • 相关阅读:
    【HDOJ】1224 Free DIY Tour
    【HDOJ】1494 跑跑卡丁车
    【HDOJ】1495 非常可乐
    ACMer
    find the nth digit
    A C
    已知六条边的边长,求四面体体积
    快速排序
    {A} + {B}
    素数回文
  • 原文地址:https://www.cnblogs.com/wjw334/p/4458284.html
Copyright © 2011-2022 走看看