15
  • 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 .
Cœur
  • 37,241
  • 25
  • 195
  • 267
Muhammad Sadiq Alvi
  • 1,099
  • 1
  • 13
  • 23

2 Answers2

12

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

Community
  • 1
  • 1
Muhammad Sadiq Alvi
  • 1,099
  • 1
  • 13
  • 23
  • The link is dead. Should learn how to use StackOverflow. Do not post links as they can go dead sometime in the future. – Neon Warge Feb 02 '17 at 02:07