Android Set LayoutManager Of RecylerView

May 11, 2018

In xml, you can assign android.support.v7.widget.GridLayoutManager or android.support.v7.widget.LinearLayoutManager to app:layoutManager.

<android.support.v7.widget.RecyclerView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutManager="android.support.v7.widget.LinearLayoutManager"
    tools:listitem="@layout/fragment_photopin_list_item"
    />

To set RecyclerView.LayoutManager programatically.

recylerView.layoutManager = LinearLayoutManager(context)
val columnCount = 3recylerView.layoutManager = GridLayoutManager(context, columnCount)

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.