how to load drawables from /drawable-hdpi instead of /drawable android? - 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:

Related

Loading local images in React Native Image component

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.

How do you add the same images of different pixel densities to the drawable directory (android studio)?

I am following the tutorials in the Big Nerd Ranch book for android but that book is structured for Eclipse + ADT.
I am trying to add an arrow icon to a button and I have folders (drawable-hdpi, drawable-mdpi, drawable-xhdpi) that contain sets of identical images. Ideally I would like these folders to appear in the drawable folder but whether I copy and paste or drag these folders it doesn't seem to work. They appear in the packages section instead, but when this happens I can't seem to reference them from xml files in the layout folder.
The best I can do is drag/copy the files (not the folder)into the drawable folder, in which case they stay there and I am able to use them. The problem with this is I can have, at most, one pixel density for the set of images that is in there. The only way I can think of is if I change the names of all of them so that the problem of overwriting is gone.
However in the mipmap folder in the ic_laucher.png folder there are four files of the same name, except there are greyed out density descriptions beside them. How is this done?
What should I do?
As you can see I have now added the images using the file system. I am still unable to reference these using the resource name however. I am still not sure why.
What you are seeing in the mipmap "folder" is just some UI magic. The Android project view in Android studio will combine all resources with the same name into a single entry like you are seeing for ic_launcher.png to make it easier to view your resources.
Behind the scenes, this still uses different folders on disk. If you open up your project in Windows Explorer, you will see separate folders for mipmap-xhdpi, mipmap-mdpi, etc.
The same is true for your drawable folders. You still want to keep your images in separate density-specific folders on disk. Android Studio will then display them to you as if they were all in the same drawable folder in the Android project view. You cannot physically move your density specific folders beneath the drawable folder.

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.

Categories

Resources