React Native設置圖片全屏背景顯示


顯示效果如下:

實現和頁面代碼如下:

1> 使用的react-navigation隱藏導航欄:

AddTopic: {screen: AddTopicScreen,navigationOptions: {
            title: ' ', // 這里不給值
            header: false, // 不顯示導航欄
            gesturesEnabled: false
        }}
    },

2>頁面代碼如下:

/**
 * Created by 思思 on 17/12/1.
 */
 
import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,
    StatusBar
} from 'react-native';

import Color from './../../Config/Color';

export default class extends Component {

    render() {
        return (
            <View style={styles.container}>
                <View>
                    <StatusBar barStyle="light-content" />
                </View>
                <Image source={require('./../../Images/images/bg.png')} style={styles.backgroundImage} />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
    },
    backgroundImage:{
        flex:1,
        alignItems:'center',
        justifyContent:'center',
        width:null,
        height:null,
        //不加這句,就是按照屏幕高度自適應
        //加上這幾,就是按照屏幕自適應
        //resizeMode:Image.resizeMode.contain,
        //祛除內部元素的白色背景
        backgroundColor:'rgba(0,0,0,0)',
      }
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM