react native Image 使用详解
来源:互联网 发布:众筹平台源码 编辑:程序博客网 时间:2024/06/05 20:05
Image是显示图片的组件。可以加载网络图片、静态资源、临时的本地图片、以及本地磁盘上的图片。本地磁盘上的图片需要在路径前加 ‘file://’。
resizeMode:组件尺寸和图片尺寸不成比例的时候调整图片的大小
cover: 在保持图片宽高比的前提下缩放图片,直到宽度和高度都大于等于容器视图的尺寸(如果容器有padding内衬的话,则相应减去)。译注:这样图片完全覆盖甚至超出容器,容器中不留任何空白。
contain: 在保持图片宽高比的前提下缩放图片,直到宽度和高度都小于等于容器视图的尺寸(如果容器有padding内衬的话,则相应减去)。译注:这样图片完全被包裹在容器中,容器中可能留有空白
stretch: 拉伸图片且不维持宽高比,直到宽高都刚好填满容器。
repeat: 重复平铺图片直到填满容器。图片会维持原始尺寸。仅iOS可用。
center: 居中不拉伸。
source:图片资源
opacity:透明度
blurRadius:模糊半径
Demo
/** * Created by on 2017/4/19. */import React, {Component} from 'react';import { StyleSheet, View, Image, ScrollView, Text, Button,} from 'react-native';export default class ImageDemo extends Component { static navigationOptions = { title: 'Image', }; state={ resizeMode:'cover' } render() { return ( <ScrollView> <View> <Image source={require('../../imgs/s99.png')}/> <View style={{flexDirection:'row',alignItems:'center',flexWrap:'wrap'}}> <Text>设置resizeMode:</Text> <Button title='cover' onPress={()=>{this.setState({resizeMode:'cover'})}}/> <Button title='contain' onPress={()=>{this.setState({resizeMode:'contain'})}}/> <Button title='stretch' onPress={()=>{this.setState({resizeMode:'stretch'})}}/> <Button title='repeat' onPress={()=>{this.setState({resizeMode:'repeat'})}}/> <Button title='center' onPress={()=>{this.setState({resizeMode:'center'})}}/> </View> <Image style={{height:100,width:100}} source={require('../../imgs/s63.png')} resizeMode={this.state.resizeMode}/> <Image style={{height:100,width:100,opacity:0.5}} source={require('../../imgs/s63.png')} /> <Image style={{height:100,width:100}} source={require('../../imgs/s63.png')} blurRadius={30}/> <Image source={{uri: 'http://h5.86.cc/walls/20141217/mid_23b73a6904487a6.jpg'}} /> </View> </ScrollView> ); }}
github下载地址
0 0
- react native Image 使用详解
- react native Image ImageBackground详解
- React Native-10.React Native Image组件详解
- React Native开源库react-native-image-crop-picker使用图解
- React Native开源库react-native-image-crop-picker使用图解
- React-native 之Image的使用
- React Native常用组件Image使用
- React Native Image使用网络图片
- react-native------Image require正确使用姿势
- react native ActivityIndicator使用详解
- react native Button 使用详解
- react native Text 使用详解
- react native Switch使用详解
- react native ScrollView 使用详解
- react native FlatList 使用详解
- react native SectionList 使用详解
- react native TextInput 使用详解
- react native Slider 使用详解
- Java中Object和Objects的基本区分
- 第 2 篇 核心技术 第 5 章 数据表的基本操作
- windows 蓝屏 BCCode代码解释
- 国家法定假日webservice自己写的工具类,需要数据库及tomcat7,jdk1.6环境
- Android获取系统资源的组件id
- react native Image 使用详解
- JavaScript网页小时钟
- 【springmvc 5】---怎么配置springmvc.xml?
- Spring+SpringMVC+Mybatis+shiro权限登录管理
- Redis Sorted Set类型介绍
- jetson tx1 上运行sudo rosdep init失败解决方法
- 微服务架构之spring cloud (前言)
- Java关键字transient和volatile
- Mac OS X mkdir: /home/test: Operation not supported