Android Horizontal RecyclerView Scroll Direction


Answer :

Assuming you use LinearLayoutManager in your RecyclerView, then you can pass true as third argument in the LinearLayoutManager constructor.

For example:

mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true)); 

If you are using the StaggeredGridLayoutManager, then you can use the setReverseLayout method it provides.


You can do it with just xml.

the app:reverseLayout="true" do the job!

<android.support.v7.widget.RecyclerView                         android:layout_width="match_parent"                         android:layout_height="wrap_content"                         android:divider="@null"                         android:orientation="horizontal"                         app:reverseLayout="true"                         app:layoutManager="android.support.v7.widget.LinearLayoutManager" /> 

XML approach using androidx:

<androidx.recyclerview.widget.RecyclerView         android:layout_width="match_parent"         android:id="@+id/my_recycler_view"         android:orientation="horizontal"         tools:listitem="@layout/my_item"         app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"          android:layout_height="wrap_content"> 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable