ReactNative全屏图片背景技巧

来源:互联网 发布:mac改了用户名进不去 编辑:程序博客网 时间:2024/05/16 02:26

找了好几个地方的资料,发现这种方式,非常靠谱。
传送门:HOW TO SET A FULL-SCREEN BACKGROUND IMAGE IN REACT NATIVE
可惜文章中并未直接亮出代码,仅放了视频,不过视频演示的还算是细致。
这个是国外网站,所以由于网络原因,等了许久才看完。
我在此处做一个总结,备忘,同时希望也能帮助到和我碰到一样问题的人:
1、Image作为root进行render

render() {    return (      <Image source={require('./assets/images/isolate/loginBg.png')} style={styles.backgroundImage} />    );  }

2、style如下:

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