ios - react native : Flex for ScrollView doesn't work

标签 ios css react-native flexbox react-native-flexbox

我有一个简单的 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>
因此,我只是将 flex:1 和 flex:5 添加到 subview 中,但在呈现的 View 中,它们都恰好适合屏幕的一半。看起来好像忽略了两个 flex 属性...

顺便说一句,使用第二个 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/

相关文章:

iphone - Flurry 分析信息

ios - 导航 Controller 上的后退按钮位置

html - 如何使用 MVC 3 在 IE6 中将文本放在图像旁边

react-native - React Native 允许用户重新排序 ScrollView 列表中的元素

react-native - 如何将 JSON 快速插入到 React Native 应用程序的 Realm 数据库中

ios - 如何为自定义UIControl添加触摸事件并在swift 5中确定触摸的项目

ios - UIStoryboardSegue & UIVisualEffectView - 完成 block 退出后模糊效果丢失

html - HTML/CSS 中的(真正)固定 DIV

html - 如何对齐两个 flexbox 元素?

listview - react native ListView : Wrong row removed when deleting