【问题标题】:How to split a column in to two subrows in react native如何在本机反应中将一列拆分为两个子行
【发布时间】:2019-12-12 05:02:17
【问题描述】:

我有这样的原生 ui 反应

我的组件的 jsx 是

  <View style={styleSheet.appItemStyle}>
    <View style={{flex:1}}>
      <Image style={styleSheet.appItemImageContainer} source={{uri: 'data:image/png;base64,'+item.icon}}/>
    </View>
    <View style={{flex:3, flexWrap: 'wrap'}}>

          <Text style={styleSheet.appItemTextStyle}>{item.appName}</Text>
          <Text style={{fontSize: 12, color: "#000"}}>{item.packageName}</Text>

    </View>

    <View style={{flex:1, alignContent: "center"}}>

        <Text style={{fontSize: 15, color:'orange'}} onPress="">COPY</Text>

  </View>
  </View>

这个 ui 的问题是,应用程序的包名显示在另一个应用程序行中, 例如,在图片中 gmail 包名称显示在设置建议应用程序名称中,我如何将一列拆分为两行,以便我的第二个文本保持在同一行而不是新行?我想要类似于下面屏幕截图的列表视图元素,我希望标题和文本在同一行,我该如何解决这个问题?我刚刚在一行中放置了两个文本元素,但它们往往会出现在下一行,为什么会发生这种情况?

【问题讨论】:

    标签: android react-native user-interface jsx


    【解决方案1】:

    最后一个屏幕截图令人困惑:它在单独的行中显示了包含 item 和 subItem 的列表项。

    据我了解,您希望将单行拆分为单行的两列。但是由于 flexbox 的 flex-direction 默认为“列”,因此您在其中的元素将按列布局。如果您添加如下 flexDirection 属性,您的 Text 组件将连续布局:

    <View style={{flex:3, flexWrap: 'wrap', flexDirection: 'row'}}>
          <Text style={styleSheet.appItemTextStyle}>{item.appName}</Text>
          <Text style={{fontSize: 12, color: "#000"}}>{item.packageName}</Text>
    </View>
    

    查看此页面:https://reactnative.dev/docs/flexbox;快速试用一下 flexbox 也很有用。

    【讨论】:

    • 对不起,我没有一个完美的例子来证明我想要什么,我真正想要的是让包名显示在应用程序名称的正下方,但是包和包之间有很多空间名称显示在第二个应用名称上方
    • 好清楚。您能否添加 styleSheet.appItemTextStyle 的详细信息?看起来它有一个将 subItem 推向底部的属性。
    【解决方案2】:
     <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF'}}>
       <View style={{flex:1}}>
        <Text>hello 1.........</Text>
        <Text>hello 1.........</Text>
        <Text>hello 1.........</Text>
        <Text>hello 1.........</Text>
        </View>
          <View style={{flex:1}}>
        <Text>hello 2.........</Text>
        <Text>hello 2.........</Text>
        <Text>hello 2.........</Text>
        <Text>hello 2.........</Text>
        </View>
      </View>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 2019-03-16
      • 2023-03-16
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多