If I define drawables for a density qualified folder
(eg drawable-hdpi), and also drawables to fall back on in drawable-nodpi
, will a high density device
use the -hdpi
over the -nodpi
?
What about if I take it a step further and also have the same setup for -land
folders.
nodpi : Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.
I'm not sure what the precedence is for nodpi
, but that should never be a problem. It sounds like you are misunderstanding the nodpi
qualifier. You should not use nodpi
as a fallback for assets that you don't provide at the device's density bucket. The correct fallback is a folder with no density qualifier (e.g. drawable/
).
If the system cannot find an asset at the device's density (e.g. it is an ldpi device and you don't have a drawable-ldpi
folder), it will fall back to a folder without a density qualifier, *not the nodpi
qualifier`.
The nodpi
qualifier is used when you want to specify a resource that will be used for all densities and that you do not want Android to scale. Assets in the other density folders (e.g. drawable-xhdpi
) will be scaled to the actual screen size. If you use the nodpi
qualifier, you should not provide that asset in any other resource folders.
It is also important to note that with screen density qualifiers, Android will also prefer to use a lower density asset over an unqualified resource. If you have an xhdpi device, but you only have a drawable
and a drawable-mdpi
folder, Android will check for the asset in the mdpi folder before the unqualified folder.
drawable-nodpi will bypass scaling and drawable will use the default scaling:
drawable-nodpi is efficient if your code will be doing its own scaling (or no scaling) and you don't want the image pre-scaled by Android.
There is also drawable-anydpi, just to make things more confusing.
drawable with no specifications will be used if an exact match on density and screen specifications does not exist. drawable-nodpi will be used after drawable.
UPDATE If you have both drawable and drawble-nodpi, the select order is either a more complex rule not documented or Android is broken. Through experimentation I confirmed that devices with screen density < xhdpi will correctly select the drawable image. Devices with screen density >= xhdpi will select the drawable-nodpi.
Selection rule: 1. Pick match to screen density, one of these:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With