I can't find any doc on the matter, is there something similar to a CollapsingToolbar
in Compose?
All I found was a mention of it here, but nothing on how to set it up
I can't find any doc on the matter, is there something similar to a CollapsingToolbar
in Compose?
All I found was a mention of it here, but nothing on how to set it up
我发现了一个由萨米尔·巴斯内特(来自Kotlin slack 频道)创建的解决方案,它对我很有用,我希望它能帮助其他人……
@Composable
fun CollapsingEffectScreen() {
val items = (1..100).map { "Item $it" }
val lazyListState = rememberLazyListState()
var scrolledY = 0f
var previousOffset = 0
LazyColumn(
Modifier.fillMaxSize(),
lazyListState,
) {
item {
Image(
painter = painterResource(id = R.drawable.recife),
contentDescription = null,
contentScale = ContentScale.FillWidth,
modifier = Modifier
.graphicsLayer {
scrolledY += lazyListState.firstVisibleItemScrollOffset - previousOffset
translationY = scrolledY * 0.5f
previousOffset = lazyListState.firstVisibleItemScrollOffset
}
.height(240.dp)
.fillMaxWidth()
)
}
items(items) {
Text(
text = it,
Modifier
.background(Color.White)
.fillMaxWidth()
.padding(8.dp)
)
}
}
}
结果如下: