简体   繁体   English

反应本机怪异的flex行为

[英]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: -20marginLeft: -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并正确设置widthheight ,或者同时设置两者的其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM