相关疑难解决方法(0)

如果第一个项目被移动,如何防止 LazyColumn 自动滚动

我使用 Jetpack Compose UI 构建一个简单的 TODO 应用程序。这个想法是有一个可以选中或取消选中的任务列表,并且选中的任务应该位于列表的末尾。

一切工作正常,除了当我检查屏幕上的第一个可见项目时,它会随着滚动位置向下移动。

我相信这与 有关LazyListState,有这样的功能:

/**
 * When the user provided custom keys for the items we can try to detect when there were
 * items added or removed before our current first visible item and keep this item
 * as the first visible one even given that its index has been changed.
 */
internal fun updateScrollPositionIfTheFirstItemWasMoved(itemsProvider: LazyListItemsProvider) {
    scrollPosition.updateScrollPositionIfTheFirstItemWasMoved(itemsProvider)
}
Run Code Online (Sandbox Code Playgroud)

所以我想禁用这种行为,但我没有找到方法。


下面是重现问题的简单代码和截屏视频。当我尝试检查“项目 0”、“项目 1”和“项目 4”时,此截屏视频中出现问题,但在检查“项目 7”和“项目 8”时,它按我预期的方式工作。

如果您选中或取消选中当前第一个可见项目的任何项目,不仅该项目位于整个列表中的第一个项目,其行为也相同。

class MainActivity : ComponentActivity() …
Run Code Online (Sandbox Code Playgroud)

android android-scroll android-jetpack-compose android-jetpack-compose-lazy-column

10
推荐指数
1
解决办法
1545
查看次数