我想要一个可滚动视图,我正在使用verticalScroll
列上的修饰符。
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
// ... I could provide more detail about the contents here but I don't think it matters.
}
当我开始垂直滚动时,视图将允许水平滚动并水平拉伸视图。对我来说这似乎不是理想的行为。
有什么办法可以阻止这种行为的发生吗?
您可以尝试通过 CompositionLocal 直接确定范围来禁用过度滚动Column
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MyListWithoutOverScroll() {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null
) {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
repeat(100) {
Text("Hello World $it")
}
}
}
}
或将其设置为Activity
level
@Composable
fun MyList() {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
repeat(100) {
Text("Hello World $it")
}
}
}
@OptIn(ExperimentalFoundationApi::class)
@AndroidEntryPoint
class MyActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CompositionLocalProvider(
LocalOverscrollConfiguration provides null
) {
MyList()
}
}
}
}
无需过度滚动,使用 CompositionLocalProvider 将其设置为 null(不拉伸)
带有过度滚动(拉伸)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)