React Native Image 总结

本文介绍React Native中图片加载的最佳实践,包括如何使用source属性引用本地图片资源,利用react-native-img-cache库进行图片缓存以提升用户体验,并讨论了在图片未加载完成前预留位置的重要性。

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

一、通过source 属性 requer img路径

二、不支持 css3 Transforms  属性

三、要给定 宽高 在图片没加载时 给图片留出位置  更好的用户体验

四、可以react-native-img-cache 库做图片缓存

react-native-img-cache该库使用是需要依赖react-native-fetch库:https://github.com/wkh237/react-native-fetch-blob)-blob(点击进入该库。

class Item extends Component {
    render() {
        return (
            <View>
                <Image source={require('./8.jpg')} style={{alignSelf:'center',width:100,height:100,opacity:0.2}}>
                    <Text style={{fontSize:20,color:'red'}}>王猛</Text>
                </Image>

            </View>
        )
    }
}
class MyImage extends Component {
    render() {
        return (
            <View style={{marginTop:10}}>

                <View style={{flexDirection:'row'}}>
                    <View style={{width:'20%'}}>
                        <Item name="王猛"/>
                    </View>
                    <View style={{width:'20%'}}>
                        <Item name="王猛"/>
                    </View >
                    <View style={{width:'20%'}}>
                        <Item name="王猛"/>
                    </View >
                    <View style={{width:'20%'}}>
                        <Item name="王猛"/>
                    </View>
                    <View style={{width:'20%'}}>
                        <Item name="王猛"/>
                    </View>
                </View>
react 组件化思想 布局适配 百分比

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值