这是完整的工作解决方案:-
LazyRows
在这里导入的是:
@Composable
fun DUME() {
val stateRowX = rememberLazyListState() // State for the first Row, X
val stateRowY = rememberLazyListState() // State for the second Row, Y
Column { // Placing two Lazy Rows one above the other for the example
LazyRow(state = stateRowY) {
items(LoremIpsum(10).values.toList()) {
Text(it)
}
}
LazyRow(state = stateRowX) {
items(LoremIpsum(10).values.toList()) {
Text(text = it)
}
}
}
//This might seem crazy
LaunchedEffect(stateRowX.firstVisibleItemScrollOffset) {
stateRowY.scrollToItem(
stateRowX.firstVisibleItemIndex,
stateRowX.firstVisibleItemScrollOffset
)
}
LaunchedEffect(stateRowY.firstVisibleItemScrollOffset) {
stateRowX.scrollToItem(
stateRowY.firstVisibleItemIndex,
stateRowY.firstVisibleItemScrollOffset
)
}
}
,这接受列表,而不是数字(大小)。其他工作方法,也可以应用于两个以上的懒惰滚动器。
上面的理查德(Richard)的答案很好,但由于循环而创建的,它会如伊万(Ivan)所描述的那样滚动时会产生滞后。解决方案很简单
androidx.compose.foundation.lazy.items
现在滚动时不会落后。现在您可以这样做: