Android Horizontal RecyclerView scroll Direction

前端 未结 12 2063
忘掉有多难
忘掉有多难 2020-12-12 16:26

I made a Horizontal RecyclerView and it works fine(thanks to this) but the direction of scroll and data are expand from left to right; then How can I change the RecyclerView

相关标签:
12条回答
  • 2020-12-12 16:32

    Try this

    I have tried all above answers it's showing me same vertically recycler view, so I have tried another example.

    1. Initialize the adapter

      private Adapter mAdapter;
      
    2. set the adapter like this

      mAdapter = new Adapter();
      LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
      recycler_view.setLayoutManager(linearLayoutManager);
      recycler_view.setAdapter(mAdapter);
      

    Hope this will also work for you For Complete code please refer this link

    0 讨论(0)
  • 2020-12-12 16:36

    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.

    0 讨论(0)
  • 2020-12-12 16:36

    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">
    
    0 讨论(0)
  • 2020-12-12 16:40

    For changing the direction of swipe you can use

    reverselayout attribute = true.

    In Kotlin,

    val layoutManager = LinearLayoutManager(this@MainActivity,LinearLayoutManager.HORIZONTAL,true)
    recyclerview.layoutManager = layoutManager

    In Java,

     LinearLayoutManager layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,true);
     recyclerview.setLayoutManager(layoutManager);
    

    Actually it reverses the layout.

    If it shows like below

    1.2..3....10

    it will change to

    10.9..8....1

    For creating Horizontal RecyclerView there are many ways.

    4 Ways To Create Horizontal RecyclerView In Android

    0 讨论(0)
  • 2020-12-12 16:48

    Try this in fragment :

    layoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
    
    mRecyclerView.setLayoutManager(layoutManager);
    
    0 讨论(0)
  • 2020-12-12 16:52

    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" />
    
    0 讨论(0)
提交回复
热议问题