Loading local images in React Native Image component - android

i'm working on an application with react native on 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
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.

Related

how to create a new resources in the mdpi folder in the xamarin

I feel irritating to develop the xamarin now since it is so not stable... i am intend to create splash screen for the android, however from what i seen from the xamarin documentation,however before i am able to achieve it, i need to add the resources to my project. Please see the following documentation
https://developer.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_1_-_android_resource_basics/
from the beginning the resource folder has been done to create all the mdpi , ldpi those folder... they skipped to teach us how to create those resource folder, so in the end, i tried to create a new folder which is named as drawable-mdpi and put some icon into it. In the end the files and folder name does not exist in the Resource.Designer.cs.
In the end my resources is unuseable... Google no solution
Earlier Xamarin project template used to have all Drawable folders by default. Now the template just has the mipmap folders. You need to create all the drawable folders manually by Right Clicking Resources Folder > Add > New Folder. Give names as "drawable-mdpi" "drawable-hdpi" and so on. You can then add images to them by Right Clicking respective folders > Add > Add Files. If the Image's Id doesn't appear in Resource.Designer.cs file, it might be due to some build error already existing. Try cleaning and re-building. Either Resource Id will appear in Resource.Designer.cs or the already existing error will pop-up fixing which your issue will be resolved.
I realized those documentation is the xamarin old documentation, by the default the xamarin created those folder already, however i dont know why the xamarin don't show when we create the new project and i still dont understand why only create 3 density which is hdpi, xhdpi and the xxdpi, is it the mdpi not longer use? I have no idea. However i will need to add those folder again in the project so i am able to see it.

Android Drawable folders aren't detected?

How do the drawable folders work nowadays?
I used to be able to just add folders named drawable-mdpi and such to get image resources, but this feature has seemingly disappeared. Image assets doesn't allow me to add image assets that aren't icons without messing them up and manually adding the drawable folders I need doesn't work any more as android can no longer find the resources.
How does android look for drawables now and how can I add prescaled images to my projects manually?

How should we use the mipmap folders added with android 4.4?

I recently installed one more Android SDK to Android Studio, the SDK version 4.4 (API level 19), and after using it with my project, it added a set of mipmap folders in the project's res folder (res/mipmap).
I neither understand why, or how to use them.
I read another question about it here on SO.
The answer to it said that:
The mipmap folders are for placing your app icons in only. Any other
drawable assets you use should be placed in the relevant drawable
folders as before.
According to this Google blogpost:
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions
different from the device’s current density.
I still don't get the reason to this.
Why cant we just place the app icons in the res/drawable folders too?
Also, if only the app icon should be placed in the mipmap folders, how do I create other drawable assets and place them in the drawable folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
Why cant we just place the app icons in the res/drawable folders too?
Oh, you can. Google doesn't recommend it, that's all.
Quoting myself from Version 6.5 of my book:
While
drawable resources might be removed when packaging an APK, such as for the
Gradle for Android split system for making density-specific editions of an app,
mipmap resources are left alone, apparently
This is because launcher icons may be pulled from a higher-density bucket than the regular device density that is used for all other drawables. Putting them in res/mipmap-*/ directories means that we won't inadvertently get rid of them as part of optimizing APK size.
(why they didn't handle this in a better way, I have no idea)
how do I create other drawable assets and place them in the drawable folders with the Android Studio Image Asset wizard? (Accessed by right clicking in the project, selecting New > Image Asset)
The Image Asset wizard only puts launcher icons in res/mipmap-*/ directories. If you choose the other icon types, they will go in res/drawable-*/. And, of course, the Image Asset wizard itself is optional.

working with assets folder or drawable folder

I am creating an app using android studio.
i created the assets folder and created sub directories under it for each activity i am using (each one has a different set of images).
But on the other hand i want to support multiply screen resolutions which as i read is supported using drawable folder's, also drawable doesn't support sub directories.
I am using API 19 at the moment.
Putting all the images in drawable folder will be a bug mass.
How can i achieve my goal of order in my images and supporting multiple screen resolutions
Thank you in advance
there are subfoldes in drawable. take a look at this http://developer.android.com/guide/practices/screens_support.html
The drawables folders allow you to save various resolution versions of an image into separate folders. The OS will choose the right asset based on the device screen density for you when you ask for #drawables/image_name. /assets is more like a normal file directory. In general if you pull from assets you need to handle resolution differences on your own.

how to load drawables from /drawable-hdpi instead of /drawable android?

When i run my app on android 2.3 emulator, without creating the /drawable directory, images are loaded from the drawable-hdpi directory.
But when i create the /drawable directory, images are loaded from the drawable instead of the drawable-hdpi directory. I have create the drawable folder to make my app to run also on android 1.5.
What should i do to load images from drawable-hdpi/mdpi/ldpi on android >=1.6?
The resources that are loaded are specific to the target that the application is being run on. If the phone is an HDPI qualified phone, then it will load those resources.. if its MDPI then it will load those resources...
You shouldn't be setting these directly, because this is handle specifically by the frameworks.
The rules used by Android to find the best matching resources at runtime are explained in this document.
Especially:

Categories

Resources