如何在 Jetpack Compose 的最后一个索引中启动 lazyRow?

时间:2021-04-16 12:20:10

标签: android kotlin android-jetpack-compose android-jetpack-compose-list

当我启动我的应用程序时,如何让 lazyRow 转到最后一个索引?

2 个答案:

答案 0 :(得分:2)

logconfig_dict = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "console": {"class": "logging.StreamHandler", "level": "INFO"},
        "null": {"class": "logging.NullHandler"},
    },
    "loggers": {
        "gunicorn.error": {"level": "INFO", "propagate": False, "handlers": ["console"]},
        "gunicorn.access": {"level": "INFO", "propagate": False, "handlers": ["null"]},
    },
}

有关更多信息,请参阅文档here

你可以对 LazyRow 做同样的事情

答案 1 :(得分:0)

您可以使用方法animateScrollToItem

类似于:

val itemsList = //... your list
val listState = rememberLazyListState()

// Remember a CoroutineScope to be able to launch
val coroutineScope = rememberCoroutineScope()

LazyColumn(state = listState) {

    items(itemsList){
        Text( "Item $it" )
    }
}

要自动启动,您可以使用:

DisposableEffect(Unit) {
    coroutineScope.launch {
        listState.animateScrollToItem(index = itemsList.size-1)
    }
    onDispose { }
}