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()

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

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

猜你喜欢

转载自blog.csdn.net/shanshan_1117/article/details/83894679