加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native图片组件Image

发布时间:2020-12-15 06:27:53 所属栏目:百科 来源:网络整理
导读:学习交流:https://gitee.com/potato512/Learn_ReactNative react-native学习交流QQ群:806870562 效果图 代码示例 import React,{Component} from 'react';import { StyleSheet,View,Image,Text} from 'react-native';const imgUrl = { uri:"https://f10.ba

学习交流:https://gitee.com/potato512/Learn_ReactNative

react-native学习交流QQ群:806870562


效果图


代码示例

import React,{Component} from 'react';
import {
    StyleSheet,View,Image,Text
} from 'react-native';

const imgUrl = {
    uri:"https://f10.baidu.com/it/u=1934388360,3660384600&fm=72"
};

type Props = {};
export default class ImagePage extends Component<Props> {
    render() {
        return(
          <View style={styles.containerStyle}>
              <View style={{flexDirection:'row',flexWrap:"wrap",justifyContent:"space-around"}}>
                  <Image style={styles.imageUrlStyle} source={imgUrl}></Image>

                  <View style={{justifyContent:"center",alignItems:"center"}}>
                      <Image style={[styles.imageUrlStyle,{resizeMode:'contain'}]}
                             source={{uri:'https://f10.baidu.com/it/u=1934388360,3660384600&fm=72'}} />
                      <Text style={{position:"absolute",top:20,left:20,color:"#FF4500",}}>
                          contain全显缩略模式
                      </Text>
                  </View>

                  <Image style={[styles.imageUrlStyle,{resizeMode:'center'}]} source={imgUrl}></Image>
                  <Image style={[styles.imageUrlStyle,{resizeMode:'stretch'}]} source={imgUrl}></Image>
              </View>

            <Image style={styles.imageLocalStyle} source={require("../../Resources/01.png")}></Image>
          </View>
        );
    }
};

const styles = StyleSheet.create({
  containerStyle: {
      marginTop:20,justifyContent:'center',alignItems:'center',},imageUrlStyle: {
      margin:10,width: 150,height: 150,backgroundColor: '#C0C0C0',// 显示模式:缩略全显contain,拉升全显(会变形)stretch,裁剪后显示(默认)cover
      resizeMode:'cover',imageLocalStyle: {
      margin:10,width: 120,height: 120,// 显示模式:缩略全显contain,拉升全显(会变形)stretch,裁剪后显示(默认)cover
      resizeMode:'contain',}
});

使用注意

1、图片来源

(1)本地图片使用source={require("../../Resources/01.png")

(2)网络图片使用source={{uri:'https://f10.baidu.com/it/u=1934388360,3660384600&fm=72'}

2、图片显示模式

(1)contain:容器完全容纳图片,图片等比例进拉伸;

(2)stretch:图片被拉伸适应容器大小,有可能会发生变形。

(3)cover:图片居中显示,没有被拉伸,超出部分被截断;

(4)center:类似cover

3、图片组件不能包含其他组件

4、图片大小

(1)本地图片:如果没有设置图片的宽高,则默认显示本地图片的实际大小

(2)网络图片:如果没有设置图片的宽高,则无法显示图片,因为网络图片没有默认大小

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读