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 = 3
recylerView.layoutManager = GridLayoutManager(context, columnCount)
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.