user1185905
user1185905

Reputation: 31

How to position a Recycler View like Google Play Store or Google Music in Android

How can I position a Recycler View like this.

It initially begins on the right edge of the view showing only just a few elements. And once you begin scrolling, all other elements starts showing.

enter image description here


enter image description here

The default Recycler View would position all elements from the leftmost part of the view.

How can I achieve this?

Upvotes: 3

Views: 2120

Answers (2)

Stefan Medack
Stefan Medack

Reputation: 2808

Another solution would be to use a ViewPager for the horizontal scrollable list of items.

With a ViewPager you can use the following snippet to indent the items:

ViewPager.setPadding(int left, int top, int right, int bottom)

Upvotes: 0

mblcdr
mblcdr

Reputation: 772

I read the other comments and felt like adding this answer. Adding a new type is overkill for achieving your goal. There's a much simpler way (Which I suppose is used in Google Play Music app).

Add horizontal padding to your RecyclerView and prevent clipping.

Here is what it would look like in xml:

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv"
    android:layout_width="match_parent"
    android:layout_height="250dp"
    android:clipToPadding="false"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" />

The key here is android:clipToPadding="false"

Upvotes: 2

Related Questions