28

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"/>

enter image description here

I want the above image, displayed horizontally. IN THE DESIGN VIEW. NOT in the application itself, I know how to do that.

easycheese
  • 5,859
  • 10
  • 53
  • 87
  • Does this help: http://stackoverflow.com/questions/28460300/how-to-build-a-horizontal-listview-with-recyclerview ? – Shaishav Aug 04 '16 at 02:32
  • Shaishav no it doesn't, this question is not about creating a horizontal recyclerview it is about displaying it in the Design View of Android Studio. – easycheese Aug 04 '16 at 02:38

3 Answers3

28

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.

Kevin Robatel
  • 8,025
  • 3
  • 44
  • 57
0

For androidx version or this days after api 28 you should set this attribute

    tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
0

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" />