【问题标题】:How can I display more elements in a react native View?如何在反应原生视图中显示更多元素?
【发布时间】:2019-09-02 13:40:11
【问题描述】:

我想在我的 react native 应用程序的主页上显示一个视图,该视图依次显示一个文本元素和一个图标,然后在这两个下方我想显示亚马逊徽标。我试过了,但它只显示了徽标。

export default class Header extends Component {
render() {
return (
  <View style={{ flex: 1, flexDirection: 'row' }}>
    <Text style={styles.Title}>Acquista!</Text>
    <Ionicons name="ios-contact" size={42} color='red' style={{ marginTop: 
65, marginLeft: 210 }} />
  </View> ,
  <Logo></Logo>

);
}
}
class Logo extends Component {
render() {
return (
  <View>
    <Image
      style={{ height: 200, width: 200, marginTop: 150 }}
      source={require('./assets/images/amazon.jpg')}
    />

  </View>
);
}
}

【问题讨论】:

  • 欢迎来到 StackOverflow!请注意,您可以使用prettier 等工具在包含代码之前对其进行格式化。

标签: ios react-native view render element


【解决方案1】:

将所有内容包装成View

return (
  <View style={{ flex: 1 }}>
    <View style={{ flex: 1, flexDirection: 'row' }}>
      <Text style={styles.Title}>Acquista!</Text>
      <Ionicons name="ios-contact" size={42} color='red' style={{ marginTop: 65, marginLeft: 210 }} />
    </View>
    <Logo />
  </View>
)

【讨论】:

  • 哦,是的...我试过了,但它只呈现了徽标,而不是图标或标题
  • @MattiaCannavò 我已经更新了我的代码,将flex: 1 包含在包装器View 上,基于此零食snack.expo.io/S1tByrfq4
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-21
  • 2018-02-02
  • 2019-07-26
  • 1970-01-01
  • 1970-01-01
  • 2022-08-06
  • 1970-01-01
相关资源
最近更新 更多