在 React Native Image 组件中加载本地图片
Loading local images in React Native Image component
我正在开发一个在 android 上使用 React Native 的应用程序。我想在屏幕上放置一些图像组件,并用一些本地图像文件加载它们。有人可以提供我应该放置文件的目录(相对于项目的根目录)吗?文档似乎没有提供任何有用的信息。
来自此处的示例:
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).
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):
- drawable-mdpi (1x)
- drawable-hdpi (1.5x)
- drawable-xhdpi (2x)
- drawable-xxhdpi (3x)
If you're missing a resolution for your asset,
Android will take the next best thing and resize it for you.
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. This process is currently being improved, a much
better workflow will be available shortly.
我正在开发一个在 android 上使用 React Native 的应用程序。我想在屏幕上放置一些图像组件,并用一些本地图像文件加载它们。有人可以提供我应该放置文件的目录(相对于项目的根目录)吗?文档似乎没有提供任何有用的信息。
来自此处的示例:
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). 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):
- drawable-mdpi (1x)
- drawable-hdpi (1.5x)
- drawable-xhdpi (2x)
- drawable-xxhdpi (3x)
If you're missing a resolution for your asset, Android will take the next best thing and resize it for you.
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. This process is currently being improved, a much better workflow will be available shortly.