如何“滚动到” ScrollableColumn的特定元素-Jetpack撰写

时间:2020-09-11 20:36:28

标签: android android-jetpack android-jetpack-compose

我想滚动到ScrollableColumn内的特定项目,但是如何在不猜测的情况下获取所需的初始scrollValue?

我希望滚动在可组合的TopAppBar结束之后开始

@ExperimentalMaterialApi
@Composable
fun Content(data: DataObj, onEditAction: () -> Unit) {
    val items = listOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "")
    val scrollState = rememberScrollState(140f)

    Surface(contentColor = Color.DarkGray) {
        ScrollableColumn(scrollState = scrollState, modifier = Modifier.fillMaxSize()) {
            TopAppBar(
                title = { Text("Edit Entry") },
                backgroundColor = Color.Transparent,
                actions = {
                    IconButton(onClick = onEditAction) {
                        Icon(asset = Icons.Filled.Edit)
                    }
                }
            )

            LazyColumnFor(items) { item ->
                Surface(Modifier.preferredHeight(50.dp).fillMaxWidth()) {
                    Text(item)
                }
            }
        }
    }
}

0 个答案:

没有答案