如何在Android Studio上修复此类型不匹配lint错误?

时间:2017-03-13 13:54:27

标签: android android-studio lint code-inspection

注释并未明确说明如何解决问题:

  

命名

     

受保护的方法无效 onMeasure int widthMeasureSpec int heightMeasureSpec

     

问题

     

概要值必须≥0且≤1073741823

这是lint抱怨的代码:

private int mMaxHeight = WITHOUT_MAX_HEIGHT_VALUE;

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    try {
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        if (mMaxHeight != WITHOUT_MAX_HEIGHT_VALUE
                && heightSize > mMaxHeight) {
            heightSize = mMaxHeight;
        }
        // First parameter of MeasureSpec.makeMeasureSpec has lint error
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.AT_MOST);
        //heightMeasureSpec = MeasureSpec.makeMeasureSpec(R.dimen.something, MeasureSpec.AT_MOST);
        getLayoutParams().height = heightSize;

    } catch (Exception e) {
        Log.e("MaxHeightListView", "Error forcing height", e);

    } finally {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

heightSize只是一个int值,也尝试使用资源维度(R.dimen.something),但问题仍然存在。

0 个答案:

没有答案