英文:
Fix item at a given pivot in Jetpack Compose's TvLazyRow/TvLazyColumn
问题
我正在使用jetpack compose for tv库中的TvLazyRow
组件,并使用PivotOffsets来将焦点项目定位到行中的固定位置。
当我将行滚动到最末尾时,固定位置的值没有被尊重,可聚焦的项目会移到最末尾。
如何在滚动到最末尾或最开头时保持位置固定?
观察到的行为:
期望的行为:
英文:
I am using the TvLazyRow
composable from the jetpack compose for tv library and using PivotOffsets to position the focused item at a fixed position in the row.
When I scroll the row to the very end, the fixed position value is not respected and the focusable item goes to the very end.
How do keep the position fixed even when scrolling to the very end or beginning?
Observed behaviour:
Desired behaviour:
答案1
得分: 4
在 TvLazyRow
或 TvLazyColumn
中,pivotOffsets
不会对列表开头或结尾的项目生效。要实现所需的行为,您可以在列表的开头和结尾添加一个虚拟的不可聚焦框,以便保持项目在所需的枢轴上。
TvLazyRow {
// 虚拟的不可聚焦占位框,用于占据空间
// 当前面的卡片被聚焦时
item { PlaceholderBox(width = 300.dp) }
items(10) {
Card()
}
// 虚拟的不可聚焦占位框,用于占据空间
// 当后面的卡片被聚焦时
item { PlaceholderBox(width = 400.dp) }
}
英文:
pivotOffsets
in TvLazyRow
or TvLazyColumn
is not respected for the items at the beginning or the end of the list. To get your desired behaviour, you can add a dummy non-focusable box at the beginning and end of the list so that it maintains your items at the desired pivots.
TvLazyRow {
// dummy non-focusable placeholder box to occupy the space
// when one of the first few cards are focused
item { PlaceholderBox(width = 300.dp) }
items(10) {
Card()
}
// dummy non-focusable placeholder box to occupy the space
// when one of the last few cards are focused
item { PlaceholderBox(width = 400.dp) }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论