Android TV Leanback RowsFragment keep focused item at the start

If you also want the last item of the row to appear at the beginning, use this ListRowPresenter:

class FocusedItemAtStartListRowPresenter(focusZoomFactor: Int) : ListRowPresenter(focusZoomFactor) {
    override fun createRowViewHolder(parent: ViewGroup): RowPresenter.ViewHolder {
        val viewHolder = super.createRowViewHolder(parent)

        with((viewHolder.view as ListRowView).gridView) {
            windowAlignment = BaseGridView.WINDOW_ALIGN_LOW_EDGE
            windowAlignmentOffsetPercent = 0f
            windowAlignmentOffset = parent.resources.getDimensionPixelSize(R.dimen.lb_browse_padding_start)
            itemAlignmentOffsetPercent = 0f
        }

        return viewHolder
    }
}

This is similar to what the Leanback Launcher does.


Faced the same issue and solved it by using a custom ListRowPresenter:

override fun createRowViewHolder(parent: ViewGroup): RowPresenter.ViewHolder {
        val viewHolder = super.createRowViewHolder(parent)

        val itemWidth = parent.resources.getDimensionPixelSize(R.dimen.epg_program_width)

        with((viewHolder as ListRowPresenter.ViewHolder).gridView) {
            itemAlignmentOffset = parent.width / 2 - itemWidth / 2 - paddingLeft
        }

        return viewHolder
    }