替换API 10的resolveSizeAndState?

时间:2013-09-18 06:45:30

标签: android

什么是resolveSizeAndState能够在API 10 android中使用的最佳方法? 我四处寻找并且卡住了。

我已经将src代码重写为此代码,无论如何都可以正常工作,但它是否安全?

private int resolveSizeAndState2(int size, int measureSpec, int childMeasuredState) {
    int result = size;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize =  MeasureSpec.getSize(measureSpec);
    switch (specMode) {
    case MeasureSpec.UNSPECIFIED:
        result = size;
        break;
    case MeasureSpec.AT_MOST:
        if (specSize < size) {
            result = specSize | MEASURED_STATE_TOO_SMALL;
        } else {
            result = size;
        }
        break;
    case MeasureSpec.EXACTLY:
        result = specSize;
        break;
    }
    return result | (childMeasuredState&MEASURED_STATE_MASK);
}

1 个答案:

答案 0 :(得分:2)

使用

ViewCompat.resolveSizeAndState()

应该有效