找了好几个地方的资料,发现这种方式,非常靠谱。
传送门:可惜文章中并未直接亮出代码,仅放了视频,不过视频演示的还算是细致。这个是国外网站,所以由于网络原因,等了许久才看完。我在此处做一个总结,备忘,同时希望也能帮助到和我碰到一样问题的人:1、Image作为root进行renderrender() { return ( ); }
2、style如下:
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)', }});