I'm working on a Leanback app and I've implemented the rows and everything via RowsFragment
and its all working great.
As for now when I go left and right within the items in the row the focused item moves to the middle of the screen and gains the focus.
Example -
I want the focused item to stay at the beginning of the row and not at the middle.
Example -
Couldn't find anything on this on the web. Would really appreciate any information regarding this.
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
}
To be complete as tvlauncher you need also set this:
fadingLeftEdge = true // to fade previous item out
But better is to use their FadingEdgeContainer, as fading edge is not really the same.
Something like this: https://github.com/bosphere/Android-FadingEdgeLayout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With