OStack程序员社区-中国程序员成长平台

标题: ios - react 原生 : Flex for ScrollView doesn't work [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:52
标题: ios - react 原生 : Flex for ScrollView doesn't work

我有一个简单的 View,它有两个 child ,另一个 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>


Best Answer-推荐答案


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 原生 : Flex for ScrollView doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47441985/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4