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,738
  • 10
  • 50
  • 85
  • Does this help: http://stackoverflow.com/questions/28460300/how-to-build-a-horizontal-listview-with-recyclerview ? – Shaishav Aug 04 '16 at 02:32
  • sonnv1368 that link is invalid. 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
  • @easycheese: http://blog.nkdroidsolutions.com/android-horizontal-vertical-recyclerview-example/ – sonnv1368 Aug 04 '16 at 02:40
  • @sonnv1368, just like I said above, this is NOT a question about how to create a recyclerview. This is about displaying it in the DESIGN VIEW of Android Studio. – easycheese Aug 04 '16 at 02:44
  • @easycheese: yes, i am sorry. – sonnv1368 Aug 04 '16 at 02:49

4 Answers4

79

Please Check this code

   <android.support.v7.widget.RecyclerView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
Atman Bhatt
  • 1,245
  • 8
  • 14
23

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
  • 7,570
  • 3
  • 41
  • 56
0

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

    tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
-7

Yes.

When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.

To create a horizontal list with RecyclerView, you might do something like this:

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

 RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
 myList.setLayoutManager(layoutManager);
Atman Bhatt
  • 1,245
  • 8
  • 14