react-native - 添加 flex :1 to contentContainerStyle 时 ScrollView 与内容一起消失

标签 react-native

当我添加固定高度样式时,它可以工作并且内容在那里,但是当我将它设置为 flex:1 (正确的方式)时, ScrollView 与内容一起消失。

我的代码:

<ScrollView contentContainerStyle={{flex:1}} showsVerticalScrollIndicator={false}>
          <View style={{padding: 5}}>
            <Text>search</Text>
          </View>
          <View style={{padding: 5}}>
            <Text>New Matches</Text>
            <ScrollView contentContainerStyle={{flex:1}} horizontal={true} showsHorizontalScrollIndicator={false}>
              <View style={{padding: 10}}>
                <Thumbnail medium circle source={require('../assets/placeholders/profile1.jpg')}/>
                <Text>Christian</Text>
              </View>
              <Text>works</Text>
              <Text>works</Text>
              <Text>works</Text>
              <Text>works</Text>
              <Text>works</Text>
            </ScrollView> 

另外,如您所见,我有两个 ScrollView 。我指的是最外面的(垂直 ScrollView )。

最佳答案

使用 flex:1 将外部 ScrollView 包装到 View 组件中风格。

<View style={{flex: 1}>
  <ScrollView contentContainerStyle={{flex:1}} showsVerticalScrollIndicator={false}>
...
  </ScrollView>
</View>

关于react-native - 添加 flex :1 to contentContainerStyle 时 ScrollView 与内容一起消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49720284/

相关文章:

javascript - 如何从对象中映射唯一且不重复的项目

reactjs - 父元素未获取子函数调用参数

android - 在 android 的 react-native 发布版本中禁用缩小和 uglify

javascript - 如何停止直到 setstate 在 React Native 中执行?

reactjs - useDispatch()错误: Could not find react-redux context value; please ensure the component is wrapped in a <Provider>

javascript - 在react-native中更新对象的状态 - 我没有使用redux

android - 进行 react native 链接时出现错误

ios - 无法在ios模拟器中调试

javascript - 如何在 React native 中动态设置图像的来源?

android - React Native PushNotification onNotification 方法