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

DecorView的测量过程

时间:2017-09-09 18:58:04      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:available   创建过程   roo   ret   hiera   group   bsp   imp   创建   

 

DecorView的MeasureSpec的创建过程

在ViewRootImpl中的mearsureHierarchy方法中有一段代码展示了DecorView的MeasureSpec的创建过程:

       childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
       childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
       performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);

看一下gerRootMeasureSpec方法:

    /**
     * Figures out the measure spec for the root view in a window based on it‘s
     * layout params.
     *
     * @param windowSize
     *            The available width or height of the window
     *
     * @param rootDimension
     *            The layout params for one dimension (width or height) of the
     *            window.
     *
     * @return The measure spec to use to measure the root view.
     */
    private static int getRootMeasureSpec(int windowSize, int rootDimension) {
        int measureSpec;
        switch (rootDimension) {

        case ViewGroup.LayoutParams.MATCH_PARENT:
            // Window can‘t resize. Force root view to be windowSize.
            measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY);
            break;
        case ViewGroup.LayoutParams.WRAP_CONTENT:
            // Window can resize. Set max size for root view.
            measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST);
            break;
        default:
            // Window wants to be an exact size. Force root view to be that size.
            measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
            break;
        }
        return measureSpec;
    }

 

DecorView的测量过程

标签:available   创建过程   roo   ret   hiera   group   bsp   imp   创建   

原文地址:http://www.cnblogs.com/huyang011/p/7498843.html

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