Ada*_*urk 2 javascript scrollview react-native
我的应用程序中有一个屏幕,其中包含“中间”内容。对于Iphone 5-8来说,此内容太长了,但对于Iphone 8S-XS Max来说只有一个屏幕。
为了解决这个问题,我放了一个simple ScrollView,适用于内容太长的内容,但是对于较大的屏幕尺寸,它会留下灰色背景,如下面的屏幕截图所示:

这是代码:
<View style={{flex: 1, width: '100%',justifyContent: 'center', alignItems: 'center', height: 900,}}>
<ScrollView style={{width: '100%', flex: 1, height: 900}}>
<ImageBackground source={require('../../assets/images/background.png')} style={{width: '100%', flex: 1, justifyContent: 'flex-start', alignItems: 'center', backgroundColor: 'background-color: rgba(0, 0, 0, 0.5)',}}>
{/*...Unimportant view code...*/}
</ImageBackground>
</ScrollView>
</View>
Run Code Online (Sandbox Code Playgroud)
如您所见,我已经将flex: 1所有重要的容器都应用了,并且尝试将height: 900上述所有容器的边界高度(例如)设置为无效。
无论设备如何,如何使滚动视图中包含的内容占据整个屏幕高度?
所以我实际上在这里的这篇中等文章中找到了答案:
https : //medium.com/@peterpme/taming-react-natives-scrollview-with-flex-144e6ff76c08
答案是,在您的<ScrollView>组件上,分配以下属性:
contentContainerStyle={{flexGrow: 1, justifyContent: 'space-between'}}
Run Code Online (Sandbox Code Playgroud)
它对我来说就像一种魅力!
| 归档时间: |
|
| 查看次数: |
632 次 |
| 最近记录: |