Is there a way to show a preview of a RecyclerView's contents as Grid in the Android Studio editor?

Viewed 12885

When I add the RecyclerView to the layout, it shows up as a list view in vertical order. I am using tools:listitem for this. Is there a way, such that it displays as grid but not as list in the Android Studio Editor?

5 Answers

If you want to see the effect only in the preview without change the app behavior you can use the "tools" namespace as you did with listitem:

<android.support.v7.widget.RecyclerView
        android:id="@+id/rcv_collection"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layoutManager="android.support.v7.widget.GridLayoutManager"
        tools:spanCount="2"
        tools:listitem="@layout/item_collection"/>

This Worked for me (AndroidX): For 3 column grid

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/rvServiceList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
    app:spanCount="3"
    tools:itemCount="20"
    tools:listitem="@layout/row_item_service" />

To show list horizontally in preview, just use these two attributes

tools:orientation="horizontal"
tools:layoutManager="android.support.v7.widget.LinearLayoutManager"

here's the final code

<android.support.v7.widget.RecyclerView
        ...
        tools:listitem="@layout/single_item_layout"
        tools:orientation="horizontal"
        tools:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
Related