gpt4 book ai didi

react-native - ScrollView 可以由 maxHeight 限制吗?

转载 作者:行者123 更新时间:2023-12-03 09:23:56 33 4
gpt4 key购买 nike

ScrollView文档提及:

Keep in mind that ScrollViews must have a bounded height in order to work, since they contain unbounded-height children into a bounded container (via a scroll interaction). In order to bound the height of a ScrollView, either set the height of the view directly (discouraged) or make sure all parent views have bounded height. Forgetting to transfer {flex: 1} down the view stack can lead to errors here, which the element inspector makes easy to debug.

是否可以将 ScrollView 与 maxHeight 绑定(bind)?这样 ScrollView 会展开,只有当 children 高于 maxHeight 时才开始滚动?

我正在尝试创建一个具有动态宽度/高度的居中模式组件,并且允许在需要时滚动。我已将高度限制为 95%。看起来 ScrollView 总是占据屏幕的 95%。如果我删除 ScrollView ,它会按预期工作。

在屏幕截图上,我希望红色框居中,而白色框不应该出现。这是 Expo Snack如果你想尝试解决我的问题。

enter image description here

有人能找到解决办法吗?或者有人可以确认这是不可能的,为什么?谢谢

最佳答案

刚刚有人帮我解决了这个问题。我需要在 ScrollView 上添加 flexGrow: 0

这是因为 ScrollView 默认有 flexGrow: 1。请注意,在 ScrollView 上使用 flex: 0 将不起作用,因为它不会覆盖默认的 flexGrow。

https://snack.expo.io/S1N027QPf

关于react-native - ScrollView 可以由 maxHeight 限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48811028/

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