Previewing horizontal recyclerview in android studio
Add a LayoutManager and set a horizontal orientation.
Here an example:
<android.support.v7.widget.RecyclerView
android:id="@+id/homesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:layout_centerVertical="true"
/>
If you are using androidx libraries:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/homesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:layout_centerVertical="true"
/>
Just use in your layout the app:layoutManager
and the android:orientation
attributes and add them also using the tools
namespace.
Something like:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/ly_item"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:orientation="horizontal"
../>
the accepted answer works accurately. For androidx just use this in your recyclerView
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"