ReactNative Image 组件

本文介绍了React Native中Image组件的基本用法,包括如何加载网络图片和本地静态资源图片,并展示了图片的不同展示模式及iOS平台特有的事件处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ReactNative Image 组件

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

/** 8、Image 组件
 * 用于显示图片的组件,包括网络图片,静态资源等
 * resizeMode 图片适应模式 cover contain stretch
 * source 图片应用地址
 * ios 支持属性 onLoad onLoadEnd onLoadStart onProgress
 *
 * 需求:显示两张图片 网络图片、静态资源图片
 *http://img.zcool.cn/community/01bf1655e514b16ac7251df840273f.jpg
 *
 */
let RnDemo = React.createClass({
    render: function () {
        return (
            <View style={styles.container}>
                <View style={styles.net}>
                    <Image style={styles.netImg}
                           source={{uri: "http://img.zcool.cn/community/01bf1655e514b16ac7251df840273f.jpg"}}
                    />
                </View>
                <View style={styles.local}>
                    <Image
                        style={styles.localImg}
                        source={require("./images/img_1.jpg")}
                    />
                </View>
            </View>
        );
    }
});
let styles = StyleSheet.create({
    container: {
        flex: 1,
        margin: 25,
        alignItems: 'center'
    },
    net: {
        marginTop: 30,
        width: 300,
        height: 240,
        justifyContent: 'center',
        alignItems: "center",
        backgroundColor: "cyan"
    },
    netImg: {
        width: 280,
        height: 200,
        // resizeMode:"cover",
        backgroundColor: "gray",
    },
    local: {
        marginTop: 30,
        width: 300,
        height: 200,
        justifyContent: 'center',
        alignItems: "center",
        backgroundColor: "yellow"
    },
    localImg: {
        width: 180,
        height: 150,
        // resizeMode:"contain",
        backgroundColor: "gray",
    }
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值