javascript - 为什么 react-native 中的默认视图宽度为 100%?为什么使用 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
在 html 中
- 默认
display=block
情况下 display=block
width=100%
默认情况下当你使用
alignItems
时,它display=block
不再是,它是display=flex
,因此宽度不是 100%为了使
width=100%
与alignItems
,你必须使用alignItems='stretch'
。或者给flex=1
孩子
虽然View
没有display=block
属性,但它只是默认行为
所以问题不在于 react-native,问题在于你对 flexbox 的理解
推荐阅读
- r - 我可以通过使用 R 中的字符来选择数据框或其他对象吗?
- java - 我创建了时钟,我想让背景透明
- markdown - Reveal.js 代码块中的 lineNumbers 使用 pandoc - 降价转换
- asp.net-core - ASP.NET Core:不通过 IIS Express 提供 Web API - 为什么?
- android - 您可能需要重新启动任何打开的编辑器才能读取新设置
- javascript - 重新连接到我的 socket.io 服务器后,没有收到从我的 android 设备发送的事件
- kotlin - 如何在 Kotlin 的另一个 ArrayList 中的 ArrayList 上存储 subList 操作?
- html - 如何在css中制作一个半圆。(没有边框和轮廓)
- scalardb - 删除记录时在 ScalarDB 中获取 InvalidUsageException
- python - (Python 2.7) 尝试将字符串附加到列表时出现语法错误