【发布时间】:2018-06-28 15:00:43
【问题描述】:
我正在练习我的 React Native 编程,但我对 Flex 布局有一个问题,我似乎不太了解
我想让我的测试应用看起来像下面这张图片
但最后,这就是我得到的。假设正确居中的“主页”文本中有一些错位,并且两个右侧图标上缺少间隙。
我尝试在两个图标上添加填充,但没有成功。
这是我的代码:
import React from 'react';
import Icon from 'react-native-vector-icons/Feather';
import { StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<View style={styles.headerContainer}>
<View style={styles.headerBrandingContainer}>
<Text style={styles.headerBranding}>Brand</Text>
</View>
<View style={styles.headerRowContainer}>
<Icon name="menu" size={30} color="white" />
<Text style={styles.headerRowPage}>Home</Text>
<View style={styles.headerRowIcons}>
<Icon name="filter" size={30} color="white" />
<Icon name="search" size={30} color="white" />
</View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
},
headerContainer: {
backgroundColor: '#3498db',
height: 180,
justifyContent: 'center',
},
headerBrandingContainer: {
marginTop: 50,
alignItems: 'center',
},
headerBranding: {
fontSize: 40,
fontWeight: '400',
letterSpacing: 1,
color: '#fff',
},
headerRowContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
margin: 10
},
headerRowIcons: {
//backgroundColor: 'red',
flexDirection: 'row',
justifyContent: 'space-between',
},
headerRowPage: {
// marginLeft:20,
fontSize: 25,
fontWeight: '500',
color: '#fff',
}
});
【问题讨论】:
-
试试
flex:1换成headerRowIcons -
@AravindS 在 headerRowIcons 上尝试了 flex:1,它会将所有内容一直推到左侧。
标签: javascript reactjs react-native flexbox