React-Native: - 如何在单个目录中为android的不同分辨率提供图像

时间:2017-05-19 13:04:09

标签: android ios image reactjs react-native

我已将图片保存在iOS和Android的单个文件夹中 目前我已经给出了如下图像名称

//For iOS
imagename.@2x.png
imagename.@3x.png

//For android
imagename.android.png

但在这里我只能为android提供一个图像 我想为不同的分辨率提供不同的图像,如mdpi,hdpi,xhdpi和xxhdpi在我保留iOS图像的同一文件夹中。

请给我解决方案。

2 个答案:

答案 0 :(得分:1)

在React Native中用于Android版本。

答案 1 :(得分:0)

具体到android和ios,您可以使用下面的反应文档中提到的特定ios和android资产结构: -

Images From Hybrid App's Resources
If you are building a hybrid app (some UIs in React Native, some UIs in platform code) you can still use images that are already bundled into the app.

For images included via Xcode asset catalogs or in the Android drawable folder, use the image name without the extension:

<Image source={{uri: 'app_icon'}} style={{width: 40, height: 40}} />
For images in the Android assets folder, use the asset:/ scheme:

<Image source={{uri: 'asset:/app_icon.png'}} style={{width: 40, height: 40}} />
These approaches provide no safety checks. It's up to you to guarantee that those images are available in the application. Also you have to specify image dimensions manually.