【问题标题】:How to space the children of a View Component React Native如何分隔视图组件 React Native 的子项
【发布时间】:2021-10-25 20:50:13
【问题描述】:

我想要一个 30px 的间隙;在我的卡片(视图)组件的所有子级之间。

return (
    <Card style={styles.screen}>
      <Text>...</Text>
      <Text>...</Text>
      <Button title='...' onPress={...} />
    </Card>
  )
const styles = StyleSheet.create({
  screen: {
    maxWidth: '80%',
    width: 200,
    paddingVertical: 30,
    justifyContent: 'center',
    alignItems: 'center',
  },
})

我希望它们都有 30px 的空间;它们之间。如何使用 React Native 的样式表做到这一点?

【问题讨论】:

  • 如果可能的话要求截图!!

标签: react-native react-native-stylesheet


【解决方案1】:
<Card style={styles.screen}>
      <Text style={styles.screenText}>
</Card>


const styles = StyleSheet.create({
  screen: {
    maxWidth: '80%',
    width: 200,
    paddingVertical: 30,
    justifyContent: 'center',
    alignItems: 'center',
  },
  screenText: {
    paddingVertical: 30, //just do custom style for each component
  }
})

【讨论】:

  • 是的,你是对的,我们可以做到这一点,但这种方式不太好。如果我有 100 个元素,我应该在每个组件中添加填充吗?
猜你喜欢
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-06
  • 1970-01-01
相关资源
最近更新 更多