![](/img/trans.png)
[英]React Native: Why don't flex justifyContent and alignItems work for child <View/>?
[英]Why is default view width is 100% in react-native? and why there is no default width when using alignItems?
我现在在 react-native 布局没有问题,只是想知道默认宽度概念的原因
下面这个脚本几乎是一样的
<View
style = {{
flex: 1
}}
>
//The view below has default width "100%"
<View
style = {{
backgroundColor: "red",
height: 60
}}
/>
</View>
<View
style = {{
alignItems: "flex-start", //Same render from left, using alignItems makes inside content having no default width
flex: 1
}}
>
//The view below has no width
<View
style = {{
backgroundColor: "red",
height: 60
}}
/>
</View>
它应该具有相同的宽度行为吗?
如果View
中的div
类比
display=block
display=block
默认为width=100%
当您使用alignItems
时,它不再是display=block
,而是display=flex
,因此宽度不是 100%
要使用alignItems
使width=100%
,您必须使用alignItems='stretch'
。 或者给孩子flex=1
虽然View
没有display=block
属性,但它只是默认行为
所以问题不在于 react-native,问题在于您对 flexbox 的理解
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.