我有一个简单的 View ,它有两个 subview ,另一个 View 和一个 ScrollView 。 ScrollView 应该比同级别的 View 高 5 倍,使用 flexbox。
<View style={{ flex: 1}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<ScrollView style={{flex: 5, backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>
顺便说一句,使用第二个 View 而不是 ScrollView 效果很好!
关于如何使用 ScrollView 实现 1:5 比例的任何想法?
最佳答案
ScrollView 是一个不继承flex
使用的组件。您要做的是将 ScrollView 包装在一个 View 中,这将创建您想要的 flex 比率。
<View style={{flex: 1}}>
<View style={{flex: 1, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<View style={{flex: 5}}>
<ScrollView style={{backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>
</View>
关于ios - react native : Flex for ScrollView doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47441985/