在我的主页上,我有4个按钮,使用flex布局进行了排列。我设置了父元素的flex: 1,这意味着它覆盖整个页面(通过backgroundColor确认)。我的问题是,当我设置alignItems: 'flex-end'时,按钮只向下移动了一点,好像flex仅覆盖了页面的一半。
以下是我的标记代码:
这是我的输出结果:
以下是我的标记代码:
<Card style={styles.cardStyle}>
<CardSection style={styles.containerStyle}>
<Button onPress={() => navigate("NewScreen")}>
New
</Button>
</CardSection>
<CardSection style={styles.containerStyle}>
<Button onPress={() => navigate("SavedScreen")}>
Saved
</Button>
</CardSection>
<CardSection style={styles.containerStyle}>
<Button onPress={() => navigate("ParametersScreen")}>
Settings
</Button>
</CardSection>
<CardSection style={styles.containerStyle}>
<Button onPress={() => navigate("FMRScreen")}>
FMR
</Button>
</CardSection>
</Card>
卡片样式:
cardStyle: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#0000ff',
}
CardSection 样式:
containerStyle: {
borderBottomWidth: 1,
padding: 5,
backgroundColor: '#fff',
borderColor: '#ddd',
height: 150,
width: 150,
borderRadius: 20,
marginTop: 10,
},
并且还需要为这些项目设置样式:
textStyle: {
color: '#007aff',
fontSize: 20,
fontWeight: '600',
},
buttonStyle: {
backgroundColor: 'rgba(255, 255, 255, 0)',
borderWidth: 0,
borderColor: '#007aff',
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
这是我的输出结果:
这是我得到的结果:
请注意,如果我删除flexWrap:'wrap',则此问题将消失,但我不能这样做!
有任何想法吗?