[英]React Native weird flex behavior
I'm trying to create a header with an image so I write this: 我试图用图像创建标题,所以我这样写:
<View style={{
flex: 1,
backgroundColor: "#FFFFFF",
padding: 20
}}
>
<View style={{ flex: 3 }}>
<Image
source={this.images.header}
style={{
flex: 1,
alignSelf: "flex-end", // HERE
resizeMode: "contain",
marginTop: -20,
marginLeft: -20
}}
/>
</View>
</View>
The weird part is alignSelf: "flex-end"
- this align the image at the left side! 怪异的部分是
alignSelf: "flex-end"
-这使图像在左侧对齐! As far as I know, it must be alignSelf: "flex-start"
to align left. 据我所知,它必须是
alignSelf: "flex-start"
才能向左对齐。
Am I wrong? 我错了吗?
PS: I use marginTop: -20
and marginLeft: -20
to stick the image to borders of the device (because of padding: 20
the container) PS:我使用
marginTop: -20
和marginLeft: -20
将图像粘贴到设备的边框(由于padding: 20
容器)
Any idea? 任何想法?
Thank in advance!
预先感谢!
I think it is because the Image
cover the whole space but the image data is resized so that you think it is only in a part of the view. 我认为这是因为
Image
覆盖了整个空间,但是图像数据已调整大小,因此您认为它仅在视图的一部分中。 Try removing flex: 1
and set the width
and height
properly or at leaset one of both. 尝试移除
flex: 1
并正确设置width
和height
,或者同时设置两者的其中之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.