Android的阵营采用可变乡土图片来源 [英] Android React Native local Image source using variable

查看:252
本文介绍了Android的阵营采用可变乡土图片来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用

<Image source={require('./img/name.png')} />

伟大的作品,但我要如何使用一个变量来代替?

Works great, but how do I use a variable instead?

<Image source={require('./img/'+rowData.imageFile+'.png')} />

文档显示这个例子 https://facebook.github.io/react-本地/文档/ images.html

// GOOD
var icon = this.props.active ? require('./my-icon-active.png') : require('./my-icon-inactive.png');
<Image source={icon} />

但是,这并不解决我的问题。

But that does not resolve my issue.

推荐答案

这工作:的https://facebook.github.io/react-native/docs/images.html#images-from-hybrid-app-s-resources

<Image source={{uri: rowData.imageFile}} style={{width: 40, height: 40}} />

只要有手动将在/安卓/应用/ src目录/主/ RES /绘制/并指定图像尺寸图像。

Just have to put the images under /android/app/src/main/res/drawable/ and specify image dimensions manually.

这篇关于Android的阵营采用可变乡土图片来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆