简体   繁体   English

在React Native Image组件中加载本地图像

[英]Loading local images in React Native Image component

i'm working on an application with react native on android. 我正在使用具有本机在Android上的应用程序。 i would like to put some Image components on the screen and load them with some local image files. 我想在屏幕上放置一些图像组件,并用一些本地图像文件加载它们。 can someone provide the directory (relative to the project's root directory) in which i should place my files ? 有人可以提供我应该放置文件的目录(相对于项目的根目录)吗? the docs don't seem to provide any useful information on this. 该文档似乎并未为此提供任何有用的信息。

From the example here: 从这里的示例:

https://facebook.github.io/react-native/docs/image.html#adding-static-resources-to-your-android-app https://facebook.github.io/react-native/docs/image.html#adding-static-resources-to-your-android-app

Adding Static Resources to your Android app Add your images as bitmap drawables to the android project (/android/app/src/main/res). 将静态资源添加到Android应用程序将图像作为位图可绘制对象添加到android项目(/ android / app / src / main / res)。 To provide different resolutions of your assets, check out using configuration qualifiers. 要提供资产的不同分辨率,请使用配置限定符检出。 Normally, you will want to put your assets in the following directories (create them under res if they don't exist): 通常,您将需要将资产放在以下目录中(如果不存在,请在res下创建它们):

  • drawable-mdpi (1x) drawable-mdpi(1x)
  • drawable-hdpi (1.5x) drawable-hdpi(1.5倍)
  • drawable-xhdpi (2x) drawable-xhdpi(2x)
  • drawable-xxhdpi (3x) drawable-xxhdpi(3x)

If you're missing a resolution for your asset, Android will take the next best thing and resize it for you. 如果您缺少资产的解决方案,Android会采取下一件最好的事情,并为您调整大小。

NOTE: App build required for new resources Any time you add a new resource to your drawables you will need to re-build your app by running react-native run-android before you can use it - reloading the JS is not enough. 注意:需要为新资源构建应用程序每当您向可绘制对象添加新资源时,您都需要通过运行react-native run-android来重新构建应用程序,然后才能使用它-重新加载JS是不够的。 This process is currently being improved, a much better workflow will be available shortly. 该过程目前正在改进中,不久将提供更好的工作流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM