RecycleView set wrong height for items

纵然是瞬间 提交于 2019-12-30 00:58:09

问题


I search answer for me, but didn't find work answer for me. I got strange error in viewing my items in RecycleView:

I use different view's for RecycleView.

I try use this code:

mLayoutManager.setAutoMeasureEnabled(true); // false doesn't work too

But it doesn't help me.

UPD 1 I forgot note this, sorry. When I start app, I have no errors (items like Normal on image) but when I started scroll my RecycleView I got problem)

UPD 2 I return back to the compile 'com.android.support:recyclerview-v7:23.1.1', but it doesn't help me (. So I add code and xml with mey RecycleView and I hope you help me.

XML:

<android.support.v7.widget.RecyclerView
    android:id="@+id/dashboard_recycle_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:scrollbars="none" />

And code:

    mRecyclerView = (RecyclerView) parent.findViewById(R.id.dashboard_recycle_view);
    mLayoutManager = new LinearLayoutManager(getContext());
    mLayoutManager.setAutoMeasureEnabled(false);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setHasFixedSize(false);
    mRecyclerView.setAdapter(mRecycleAdapter);

回答1:


Set wrap_content for the recyclerview and for your viewholder layout parent. This worked for me.




回答2:


Set wrap_content instead of match_parent ( if you set as match_parent ) as that causes the layout to match the parent giving you the large spaces.




回答3:


I encountered the same problem. If you only change RecyclerView to wrap_content, the startup page looks fine but you will get blank space after swiping up.

Solution: In addition to change android:layout_height of RecyclerView to wrap_content, you should also go to the layout XML file where your RecyclerView items are, and modify the surrounding RelativeLayout's android:layout_height attribute to wrap_content.

Please refer to this thread.



来源:https://stackoverflow.com/questions/35747268/recycleview-set-wrong-height-for-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!