天天看点

java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasur

今天自定义Recycleview时,调用

adapter.notifyDataSetChanged();
           

报异常,异常信息如下:

 java.lang.IllegalStateException: View with id 2131230785: com.example.smartcity.widget.viewpageRecycleview.PageRecyclerView#onMeasure() did not set the measured dimension by calling setMeasuredDimension()

java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasur

解决方法:在onMeasure()里添加:setMeasuredDimension()

@Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        setMeasuredDimension(widthSpec, heightSpec);
        super.onMeasure(widthSpec, heightSpec);
        shortestDistance = getMeasuredWidth() / 3;
    }
           

继续阅读