自定义View的测量问题

Android群英传 3.2View的测量代码

@Override

    protected void onMeasure(int widthMeasureSpec,

        int heightMeasureSpec) {

            setMeasuredDimension(

                measureWidth(widthMeasureSpec),

                measureHeight(heightMeasureSpec));

}

private int measureWidth(int measureSpec) {

    int result = 0;

    int specMode = MeasureSpec.getMode(measureSpec);

    int specSize = MeasureSpec.getSize(measureSpec);

    if (specMode == MeasureSpec.EXACTLY) {

            result = specSize;

    } else {

            result = 200;

            if (specMode == MeasureSpec.AT_MOST) {

                    result = Math.min(result, specSize);

            }

    }

    return result;

}

请问下划线的if语句有什么作用呢?前面result = 200 不是已经设置自定义View的wrap_content默认值为200px了么?

道可道非常道
浏览 1483回答 3
3回答

我的南方

子控件的大小,不超过父控件允许的最大控件,如果不等吧最小的的值赋值给result

慕的地8582982

UWEGBJNRKGERXOZUFTPZIMWSUSPJTNNUWPFFPGGKMVQDJRCMZWHUEMFKNOZHYBGQWYJJJTLGULTAZRXUIWTQRRPGMTWVSTXYPPBWCESSJHBLIUZGWCSTJQWXYDQQXEJHBBOPGJEEBVLULJNFPAKBXYVLCKWKKUKNKKKIAJFTWYZALLPLPMMHLYVPFDQEVYSPTBIYMTJZDEVJFMTKOGWDHHWMNTLUBOHSPLZTPLCSJTGNAJAZECEDGQXHFWQARQGTNOLGNTQEJMTTLGKXHBCFCCCDOYIZCOJWAYFKLTNHFSSDPVMNOEIFWWTQNHOIIBSAHIJZQKKBSWUAECFMIZPGUYYYIFTAAAPPWCMQRJQISGKZSBVPMXOURTFCPZCDFMUWCZMXOTLNHEKUSZXCSVWJTAIPMRZCGXDKHRLINRFZNAAFMEUSFDEBYONHWNRYEPAHNEGOBVJQNKSSMTGBFAKTKXOSGGDYVJMDKDHJDXESIMUHRKBYALPMALCOCCRISMGAKRKENDNELPQECLZBSLICQKBEEICKOFQMGHEXLFWEMIGQXKUIJIFWXEOPJIMTJXVFSJDEYJUPVJEISPAWNVUULIPTKHXRLOSTXULFMCTLPITDRDYFVCMRETVVPIMMRRJEVZPCARBOJICJECNTBPWJKGEOOVJJTVXXTOCZCKQGOYGDQAGDLRBIMCWJBFCJQUHVHXBIIMTUUSDPUICAAVLVESRBFPQEDHOBWNDMKYIGZGQKWTTHEOVMLUOQMGRXHJKTRBWUEYTAXOULDVDHCGDAHQTURJXIOQXUAYYOFSWDHUTCABMIUHYSCJZQBKGHKHALMLZUEKNSTRPWMTTAWMQUOLBLAEJDRFMZHRJHBCDRVSWDNHLS
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android
Java