简体   繁体   English

用flex容器在Native //背景图像上反应吗?

[英]React Native // Background Image with flex container over it?

I'm trying to add a background image to my app, and I know the traditional way of doing it with the following style: 我正在尝试将背景图片添加到我的应用中,并且我知道使用以下样式的传统方式:

animatedBackground: {
    alignItems: 'center',
    resizeMode: 'stretch',
    width: null
},

But my app is a little more complex, and I need to have a flex container over the background to display my information correctly (like adding another image over the background image). 但是我的应用程序稍微复杂一点,我需要在背景上有一个flex容器才能正确显示我的信息(例如在背景图像上添加另一个图像)。 Therefore, I can't seem to be able to properly do this. 因此,我似乎无法正确执行此操作。 This is my code for the screen: 这是我的屏幕代码:

render() {
    return (


        <View style = {styles.container}>

        <Image
            source={require('../images/background.gif')}
            style={styles.animatedBackground} />


            <Image
            source={require('../images/trophy.png')}
            style={{width: 280, alignItems: 'center', height: 280}}
            />

            <Text style={styles.welcome}>
            BreakFree
            </Text>

            <View style = {{flexDirection: 'row'}}>
                <Button onPress = { this.login } style ={styles.tapToStart}>
                    Login
                </Button>

                <Button onPress = { this.signupUser } style ={styles.tapToStart}>
                    Signup
                </Button>
            </View>


        </View>
    );
}

Where "container" is “容器”在哪里

container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#58C2E9',
},

import React from 'react';

import {Dimensions, Image, ImageBackground, Text, TouchableOpacity, View} from 'react-native';

const {width, height} = Dimensions.get('window')

render() {
    return (
        <ImageBackground source={require('../path/background_image.png')} style={{
            width: width,
            height: height,
            flex: 1,
            flexDirection: 'column',
            justifyContent: 'center',
            alignItems: 'center',
        }}>


            <Image source={require('../path/logo.png')} resizeMode={'contain'}/>

        </ImageBackground>
    );
}

you can try this way. 您可以尝试这种方式。 if any text or button put in View. 如果在视图中放入任何文本或按钮。

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

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