RecyclerView crashes when “scrapped or attached views may not be recycled”

前端 未结 27 2886
灰色年华
灰色年华 2020-11-29 19:50

I\'m using a simple implementation of RecyclerView taken from the Android website using a StaggeredGridLayoutManager and I keep getting this error

27条回答
  •  心在旅途
    2020-11-29 20:05

    this exception is not cause of

    android:animateLayoutChanges

    or

    android:focusableInTouchMode

    this final correct answer is just because you set a WRONG LayoutParams.

        nameLP = new LinearLayout.LayoutParams(context.getResources().getDisplayMetrics().widthPixels, LinearLayout.LayoutParams.WRAP_CONTENT);
        nameLP2 = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
    

    the nameLP is OK. the nameLP2 occur the crash .bug is here.

    I try all of answers of this page. trust me.

提交回复
热议问题