react-native - 在 React Native 中创建简单的网格布局
问题描述
我正在尝试在我的 React Native 应用程序中创建以下布局,但无法正确设置。电话号码、地址和时间表目前位于屏幕中间,“互动部分”位于屏幕底部。
我在这里做错了什么?我很感激这个布局的一些帮助。谢谢!
顺便说一句,在下图中,我放置了边框以向您展示我想要实现的目标。我实际上不想看到联系信息、日程安排或互动部分的任何边界。整个事情应该只是漂浮在白色背景上。
这是我的组件中的代码:
<View style={styles.container}>
<View style={styles.title}>
<Text style={styles.titleText}>Global Enterprises</Text>
</View>
<View style={styles.contactInfoSection}>
<View style={styles.phoneNumberSection}>
<View>
<Text>212.555.1234</Text>
</View>
<View>
<Text>1 Global Way</Text>
<Text>New York, NY 12345</Text>
</View>
</View>
<View style={styles.scheduleSection}>
<Text>Mon - Fri 8:30 - 5:30</Text>
<Text>Sat - Sun Closed</Text>
</View>
</View>
<View>
<Text style={styles.interactSection}>Other stuff</Text>
</View>
</View>
这是这个特定屏幕的样式表:
const styles = StyleSheet.create(
{
contactInfoSection: {
alignContent: 'flex-start',
alignItems: 'flex-start',
alignSelf: 'flex-start',
flex: 2,
flexDirection: 'row',
marginTop: 20
},
container: {
alignContent: 'flex-start',
flex: 1,
flexGrow: 1,
padding: 20
},
interactSection: {
flex: 3
},
locationSection: {
alignItems: 'center',
flex: 1
},
phoneNumberSection: {
alignContent: 'center',
alignItems: 'center',
alignSelf: 'center',
flex: 1
},
scheduleSection: {
alignContent: 'center',
alignItems: 'center',
alignSelf: 'center',
flex: 1
},
title: {
alignItems: 'center',
flex: 1,
marginTop: 5
},
titleText: {
fontSize: 17,
fontWeight: 'bold'
}
}
);
export { styles };
解决方案
您需要更新contactInfoSection
和title
样式。请修改
这个
contactInfoSection: {
alignContent: 'flex-start',
alignItems: 'flex-start',
alignSelf: 'flex-start',
flex: 2,
flexDirection: 'row',
marginTop: 20,
},
title: {
alignItems: 'center',
flex: 1,
marginTop: 5,
},
对此
contactInfoSection: {
flexDirection: 'row',
marginTop: 20,
},
title: {
alignItems: 'center',
marginTop: 5,
},
祝你好运
推荐阅读
- storage - 从谷歌云存储查看图像?
- kubernetes - 如何在 stable/prometheus 图表 values.yaml 中包含来自另一个 yaml 文件的普罗米修斯规则?
- mysql - 如何在 Perl 中从 MySQL 获取最后一个错误
- c# - 从 DB.Entity 设置默认 POCO 属性值
- typescript - 打字稿:使接口属性成为必需
- pyomo - Pyomo:我们可以设置一个空索引的参数吗?
- opencv - opencv:CV_8SC1 vs CV_8UC1 - 负值是否映射到/视为0?
- r - 使用函数更改ggplot中的轴中断
- elasticsearch - 文档的 Elasticsearch 索引如何变成倒排索引?
- javascript - 有没有办法将 JSON 发送到 php 处理器而无需