繁体   English   中英

React Native:为什么不在 <View> 里面 <ScrollView> 工作?

[英]React Native: Why doesn't setting flexGrow on a <View> inside a <ScrollView> work?

在我的React Native应用中,我有以下代码:

  <View style={{flex: 1}}>
    <View style={{backgroundColor: 'black', height: 50}}/>
    <ScrollView style={{borderWidth: 1, borderColor: 'red', flex: 1}}>
      <Text style={{
        borderWidth: 1,
        borderColor: 'blue',
        flexGrow: 1
      }}>aaa</Text>
      <Text style={{
        borderWidth: 1,
        borderColor: 'blue',
        flexGrow: 1
      }}>bbb</Text>
    </ScrollView>
  </View>

在此处输入图片说明

请注意,我在aaabbb <View>上具有flexGrow: 1 ,但是它们不会增长以填充垂直空间。 如果我将<ScrollView>交换为<View> ,则子级会填充它。 为什么是这样?

在这里看看ScrollView文档: https : //facebook.github.io/react-native/docs/scrollview.html#contentcontainerstyle

您缺少的关键是指定容器样式。 维护人员不会对您的期望做出任何假设,特别是因为根据您过去的经验可能会造成混淆。 您绝对可以得到您想要的工作。

这是添加到您的代码中的示例: https : //snack.expo.io/SkeLDj4EH

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM