I suppose, with a known number of elements in the adapter, you can write with a simple extension for the GridLayoutManager
class.
I just needed this, so here is a working solution ...
fun getGridManagerLastRowCenter(ctx: Context, spanCount: Int, itemsCount: Int, @RecyclerView.Orientation orientation :Int, reverseLayout: Boolean) : GridLayoutManager {
Use with a simple call
rv.layoutManager = UtilsListAco.getGridManagerLastRowCenter( ctx, 3, items.size, RecyclerView.VERTICAL, false)
source share