我在
BottomSheetDialogFragment
中使用了LazyColumn
,但是如果向上滚动LazyColumn
列表,则BottomSheet
对话框会滚动而不是LazyColumn
列表。似乎BottomSheetDialogFragment
截取了用户的触摸输入。
效果如下图所示:
如何在BottomSheetDialogFragment
内正确使用LazyColumn
?
MyBottomSheetDialogFragment.kt:
class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Header", color = Color.Black)
LazyColumn(
Modifier
.weight(1f)
.fillMaxWidth()) {
items(100) {
Text("Item $it", Modifier.fillMaxWidth(), Color.Black)
}
}
}
}
}
}
}
并使用以下代码进行显示:
MyBottomSheetDialogFragment().show(activity.supportFragmentManager, null)
当我们使用XML RecyclerView
列表时,为了解决这个问题,我们不得不像这里所描述的那样用NestedScrollView
包装RecyclerView
列表。但是如何在Jetpack Compose中解决这个问题呢?
modifier = Modifier.verticalScroll(rememberScrollState())
来解决。文档还提到:“为了解决这个问题,请确保将可滚动修饰符设置为这些类型的嵌套组合”。 - Edward van Raak