问题
- 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:
- And Here is what I am getting:
- 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