[英]React Native: Flex for ScrollView doesn't work
我有一个简单的View,它有两个孩子,另一个View和ScrollView。 使用flexbox时,ScrollView应该比相同级别的View高5倍。
<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中,这将创建您想要的弹性比率。
<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>
要实现1:5的屏幕比例,相对于父视图具有子组件View和ScrollView,可以按以下方式进行编码:
<View style={{ flex: 1}}>
<View style={{flex: 1/5, backgroundColor: 'powderblue'}}>
<Text>Add new stuff</Text>
<Button title="Browse Gallery" onPress={ openGallery } />
</View>
<ScrollView style={{flex: 4/5, backgroundColor: 'skyblue'}}>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
<Text style={{ fontSize: 100}}>Scroll me plz</Text>
</ScrollView>
</View>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.