gpt4 book ai didi

android - 在传统的 android ViewPager 中滚动 LazyRow 的问题

转载 作者:行者123 更新时间:2023-12-04 23:38:36 25 4
gpt4 key购买 nike

使用 jetpack compose 互操作性 API 时,在预构建的 ViewPager 中使用 LazyRow 会导致滚动问题。
当试图滚动 LazyRow 中的项目时,ViewPager 会移动。我们有什么办法可以防止这种情况发生吗?
撰写 View

<androidx.compose.ui.platform.ComposeView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
在 fragment 中设置 View
binding.composeView.setContent {
HorizontalScrollableView(listOfCards)
}
以及写在 compose 中的 View
@Composable
fun HorizontalScrollableView(listOfCards: List<Cards>) {
Column(
modifier = Modifier
.background(color = colorResource(R.color.grey10))
) {
Text(
text = "Items",
color = colors.primary,
style = typography.subheadBold,
fontSize = 15.sp,
modifier = Modifier.padding(start = 16.dp, top = 10.dp, end = 16.dp)
)
LazyRow(contentPadding = PaddingValues(end = 16.dp)) {
items(
items = listOfCards,
key = { listOfCards.id }
) {
RenderCard(it)
}
}
}
}

最佳答案

这是您遇到的正常行为。此处描述了类似的问题。
Link
或者,可以控制惰性行手势。

Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = { /* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
在 onPress 你可以取消你想要的滚动状态
除了作曲,我们也是这样解决的。
Link
我希望这有帮助。好工作

关于android - 在传统的 android ViewPager 中滚动 LazyRow 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68038792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com