How to make recycler view start adding items from center?

感情迁移 提交于 2021-02-08 12:20:13

问题


  • I have a recyclerView with "Horziontal Linear Layout" as layout manager.
  • Recycler View is in a frame layout, with layout_gravity = "center", and layout_width="wrap_content"
  • I want recycler view start adding items from center.
  • Here is what I want:

enter image description here

enter image description here

enter image description here

  • And Here is what I am getting:

enter image description here

  • You can see that in the last image items are added from left. I want it to add items from center as shown in the first three images .

回答1:


i had same issue and solved like this for my horizontal RecyclerView:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="wrap_content"
        android:layout_height="68dp"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager" />

Here the main part is android:layout_centerHorizontal="true" and layout_width="wrap_content"




回答2:


Solved:

How do I make WRAP_CONTENT work on a RecyclerView

This was the solution, I had to enforce the wrap_content for recycler view, So a custom Layout manager worked for me. Hope this will help others:)



来源:https://stackoverflow.com/questions/30259741/how-to-make-recycler-view-start-adding-items-from-center

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