React Native--Image控件
发布时间:2020-12-15 08:15:43 所属栏目:百科 来源:网络整理
导读:基本用法 加载本地图片 Image source ={ require ( './img/baidu.png' )}/ 加载App内资源图片 Image source = {{ uri : ' ic _ launcher '}} style = {{ width : 140, height : 140}} / 加载网络图片 Image source = {{ uri :' http ://172 . 17 . 137 . 68
基本用法加载本地图片<Image source={require('./img/baidu.png')}/>
加载App内资源图片<Image source={{uri: 'ic_launcher'}} style={{width: 140,height: 140}} />
加载网络图片<Image source={{uri:'http://172.17.137.68/heqiang/2.jpg'}} style={{width: 200,height: 200}}/>
资源图片和网络图片必须声明图片寬高,否则不显示。 适配不同平台有时我们希望在不同平台之间用不同的图片 代码import React,{ Component } from 'react'; import { AppRegistry,StyleSheet,Text,View,Image } from 'react-native'; class HelloWorldAppp extends Component{ render() { console.log("render()"); return ( <View> <Text style={styles.title_text}>本地图片</Text> <Image source={require('./img/baidu.png')}/> <Text style={styles.title_text}>资源图片</Text> <Image source={{uri: 'ic_launcher'}} style={{width: 140,height: 140}} /> <Text style={styles.title_text}>网络图片</Text> <Image source={{uri:'http://*******.jpg'}} style={{width: 200,height: 200}}/> ); } } AppRegistry.registerComponent('AwesomeProject',() => HelloWorldAppp); const styles = StyleSheet.create({ title_text:{ fontSize:18,} });
效果图回调函数和属性
<Image source={{uri:'http://172.17.137.68/heqiang/23.jpg'}} style={{width: 200,height: 200}}
onLoad={function(){console.log("onLoad");}}
onLayout={function(){console.log("onLayout");}}
onLoadStart={function(){console.log("onLoadStart");}}
onLoadEnd={function(){console.log("onLoadEnd");}}
/>
<Image source={{uri:'http://172.17.137.68/heqiang/test.png'}} style={{width: 200,height: 200,backgroundColor: 'grey',resizeMode: Image.resizeMode.contain}} resizeMode={Image.resizeMode.center} />
样式风格
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |