找了好几个地方的资料,发现这种方式,很是靠谱。
传送门:HOW TO SET A FULL-SCREEN BACKGROUND IMAGE IN REACT NATIVE
惋惜文章中并未直接亮出代码,仅放了视频,不过视频演示的还算是细致。
这个是国外网站,因此因为网络缘由,等了许久才看完。
我在此处作一个总结,备忘,同时但愿也能帮助到和我碰到同样问题的人:
一、Image做为root进行renderreact
render() { return ( <Image source={require('./assets/images/isolate/loginBg.png')} style={styles.backgroundImage} /> ); }
二、style以下:react-native
const styles = StyleSheet.create({ backgroundImage:{ flex:1, alignItems:'center', justifyContent:'center', width:null, height:null, //不加这句,就是按照屏幕高度自适应 //加上这几,就是按照屏幕自适应 //resizeMode:Image.resizeMode.contain, //祛除内部元素的白色背景 backgroundColor:'rgba(0,0,0,0)', } });