css - React Native View 不包含在该 View 中作为子项编写的 Text 组件?
问题描述
在代码中,您可以看到我在 Component 中创建了一个嵌套视图,并为父视图设置了边框颜色“绿色”和子视图的样式,边框颜色为“黄色”。子视图包含一些文本。我的问题是为什么文本组件不在边界内,您可以在 image_2 中看到输出?
class Header extends React.Component{
render(){
return(
<View style={styles.topView}>
<View style={styles.header}>
<Text>MENUBAR</Text>
<Text>TITLE</Text>
<Text>HOME</Text>
</View>
</View>
)
}
}
const styles=StyleSheet.create({
topView:{
backgroundColor : '#87cefa',
borderColor : 'green',
borderWidth : 2
},
header : {
flex:1,
flexDirection : 'row',
marginTop : '10%',
backgroundColor : '#FFF000',
borderColor : 'yellow',
borderWidth : 3,
alignSelf : 'stretch'
}
})
代码输入图像:-
输出图像:-
解决方案
您可以尝试将 css 更改为此;
topView:{
minHeight : 90, // flex: 1 // if you want it as full screen.
backgroundColor : '#87cefa',
borderColor : 'green',
borderWidth : 2,
justifyContent: 'center',
textAlign: 'center'
},
header : {
flexDirection : 'row',
backgroundColor : '#FFF000',
borderColor : 'yellow',
borderWidth : 3,
}
希望这会帮助你。
推荐阅读
- discord - discord.js 嵌入的空消息问题
- firebase - 使用 auth.uid 限制对 Firebase-Database 的访问不起作用
- php - Facebook Graph API v3.1 开发人员的访问令牌权限限制
- python - Pandas 按多列和最大值分组
- gams-math - 从 GAM 导出到文本文件
- mysql - mysql - 从 2 个不同的表中选择不同的行
- python - python 相当于 vlookup 的系列和数据框
- docker - 使用 fluentd 监控 Redis
- rxjs6 - 如何理解这个 Observable 配方?
- flutter - 原材料按钮 onPressed 不起作用