修复 Jetpack Compose 的 TvLazyRow/TvLazyColumn 中给定枢轴处的项目

Dav*_*vid 3 android-tv android-jetpack-compose android-jetpack-compose-tv

我正在使用jetpack compose for tv 库TvLazyRow中的可组合项,并使用PivotOffsets将焦点项目定位在行中的固定位置。

当我将行滚动到最后时,不遵守固定位置值,并且可聚焦的项目会转到最后。

即使滚动到末尾或开头,如何保持位置固定?

观察到的行为:

期望的行为:

Vig*_*aut 5

pivotOffsets对于列表开头或结尾的项目,不考虑inTvLazyRow或。TvLazyColumn为了获得您想要的行为,您可以在列表的开头和结尾添加一个虚拟的不可聚焦框,以便它将您的项目保持在所需的枢轴处。

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) }

}
Run Code Online (Sandbox Code Playgroud)