Aka*_*min 13 android android-viewpager android-jetpack android-jetpack-compose
使用 jetpack compose 互操作性 API 时,在预构建的 ViewPager 中使用 LazyRow 会导致滚动问题。
当尝试滚动 LazyRow 内的项目时,ViewPager 会移动。我们有什么办法可以防止这种情况发生吗?
撰写视图
<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" />
Run Code Online (Sandbox Code Playgroud)
在片段中设置视图
binding.composeView.setContent {
HorizontalScrollableView(listOfCards)
}
Run Code Online (Sandbox Code Playgroud)
以及用 compose 编写的视图
@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)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是您遇到的正常行为。此处描述了类似的问题。
或者,可以控制惰性行手势。
Modifier.pointerInput(Unit) {
detectTapGestures(
onPress = { /* Called when the gesture starts */ },
onDoubleTap = { /* Called on Double Tap */ },
onLongPress = { /* Called on Long Press */ },
onTap = { /* Called on Tap */ }
)
}
Run Code Online (Sandbox Code Playgroud)
在onPress中你可以取消你想要的滚动状态
除了作曲之外,我们也是这样解决的。
我希望这有帮助。好工作
| 归档时间: |
|
| 查看次数: |
1810 次 |
| 最近记录: |