代码之家  ›  专栏  ›  技术社区  ›  Boss Nass

React本机Flex Box Align

  •  0
  • Boss Nass  · 技术社区  · 6 年前

    我正在尝试在和ImageBackground组件中对齐图像,尽管无论我做什么,它似乎都没有遵循flexbox规则。

    下面是期望的结果

    enter image description here

    但我现在正在

    enter image description here

    render () {
    console.log(this.props.data.attributes.main_image_url)
    return (
      <TouchableOpacity onPress={this._handlePress} style={styles.container}>
        <ImageBackground source={{uri: "https:"+this.props.data.attributes.main_image_url}} style={styles.background}>
          <View style={styles.logoContainer}>
            <Image
              // defaultSource={require('../Images/logo-placeholder.png')}
              source={{uri: "https:"+this.props.data.attributes.logo_url}}
              resizeMode="contain"
              style={styles.logo}
            />
          </View>
        </ImageBackground>
      </TouchableOpacity>
    )
    

    }

    风格

        container: {
        marginBottom: Metrics.doubleSection,
        flex: 1,
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'stretch',
      },
      background: {
        height: Metrics.screenWidth / 2,
        width: Metrics.screenWidth-(Metrics.baseMargin*2),
        margin: Metrics.baseMargin
      },
      logoContainer: {
        backgroundColor: Colors.coal,
        justifyContent: 'flex-end',
        alignItems: 'left',
        left: Metrics.doubleBaseMargin,
        height: Metrics.images.xl,
        width: Metrics.images.xl
      },
      logo: {
        height: Metrics.images.xl,
        width: Metrics.images.xl
      }
    
    2 回复  |  直到 6 年前
        1
  •  1
  •   Rutvik Bhatt    6 年前

    换衣服 logoContainer 样式如下所示 position:'absolute' and set bottom:negative value

    logoContainer: {
        backgroundColor: Colors.coal,
        justifyContent: 'flex-end',
        alignItems: 'flex-start',
        position:'absolute', // set position to absolute 
        bottom:-10, //give relative value here
        left: Metrics.doubleBaseMargin,
        height: Metrics.images.xl,
        width: Metrics.images.xl
      },