美文网首页
【转】ReactNative全屏图片背景技巧

【转】ReactNative全屏图片背景技巧

作者: RichyLeo | 来源:发表于2017-03-15 00:41 被阅读2433次

之前作Cell定制,以Image为背景,遇到此问题。搜索良久..
今转载留存,供大家参考

传送门: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、Image.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)',
  }
});

相关文章

网友评论

      本文标题:【转】ReactNative全屏图片背景技巧

      本文链接:https://www.haomeiwen.com/subject/pdbknttx.html