Reputation: 5899
I am using the tools:listitem attribute to show my views in the design layout with a recyclerview. Problem is, they always show up in a vertical list. Is there a way to have the Design Layout Editor display them horizontally?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@android:layout/simple_list_item_checked"/>
I want the above image, displayed horizontally. IN THE DESIGN VIEW. NOT in the application itself, I know how to do that.
Upvotes: 29
Views: 14405
Reputation: 424
apply these attributes for recyclerview:
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
Example:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPokemonTeamPokemon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
tools:listitem="@layout/item_pokemon_image"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="6" />
Upvotes: 0
Reputation: 89
For androidx version or this days after api 28 you should set this attribute
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
Upvotes: 1
Reputation: 8386
Complete example that works:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:orientation="horizontal"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/view_item" />
PS: you can replace androidx.recyclerview.widget.LinearLayoutManager
by android.support.v7.widget.LinearLayoutManager
if you don't use AndroidX.
Upvotes: 29