2

I have 2 recycler views. 1 horizontal and 1 vertical. In the design page the elements for the first recycler are horizontal and for the second are vertical, but when I run then app both of them are vertical and I can't figure out what's the problem.

  <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/selected_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="horizontal"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/name_edit_text"
        tools:listItem="@layout/item_participant_selected" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="120dp"
        android:layout_marginBottom="@dimen/participants_padding_bottom"
        android:clipToPadding="false"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintEnd_toEndOf="@id/selected_recycler_view"
        app:layout_constraintStart_toStartOf="@id/selected_recycler_view"
        app:layout_constraintTop_toBottomOf="@id/selected_recycler_view"
        tools:listItem="@layout/item_participant" /> 
Netheru
  • 301
  • 1
  • 5
  • 19

4 Answers4

5

Xml -

android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"

Programmatically -

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
Prateek Kumar
  • 321
  • 1
  • 3
  • 16
2

It can easily be done through programatically

XML:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="120dp"
    android:layout_marginBottom="@dimen/participants_padding_bottom"
    app:layout_constraintEnd_toEndOf="@id/selected_recycler_view"
    app:layout_constraintStart_toStartOf="@id/selected_recycler_view"
    app:layout_constraintTop_toBottomOf="@id/selected_recycler_view"
    tools:listItem="@layout/item_participant" /> 

Java:

LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recycler_view.setLayoutManager(layoutManager);

Kotlin:

recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
Ali Azaz Alam
  • 1,782
  • 1
  • 16
  • 27
0

Try Horizontal linear layout manager as I have commneted

LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43
0

since you do not set the LayoutManager in .xml you just should use

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
Aiko West
  • 791
  • 1
  • 10
  • 30