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

2017-03-15  本文已影响2433人  RichyLeo

之前作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)',
  }
});
上一篇 下一篇

猜你喜欢

热点阅读