2

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);
}
4

1 回答 1

2

使用

ViewCompat.resolveSizeAndState()

应该管用

于 2015-10-28T11:50:31.910 回答