Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will a density qualified drawable folder or drawable-nodpi take precedence?

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.

like image 648
theblang Avatar asked Jul 10 '14 16:07

theblang


People also ask

What is Nodpi?

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.

What does the drawable folder contains?

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.

What is drawable folder in Android directory?

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.


2 Answers

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.

like image 165
Bryan Herbst Avatar answered Sep 27 '22 23:09

Bryan Herbst


drawable-nodpi will bypass scaling and drawable will use the default scaling:

  • mdpi = 1x
  • hdpi = 1.5x
  • xhdpi = 2x
  • xxhdpi = 3x
  • xxxhdpi = 4x

    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:

    • drawable-ldpi
    • drawable-mdpi
    • drawable-hdpi
    • drawable-xhdpi
    • drawable-xxhdpi
    • drawable-xxxhdpi
    1. If no match on density, then select one of these
    • drawable (automatic scaling mdpi=none... xxxhdpi=4x)
    • drawable-nodpi (no scaling)
    • drawable-tvdpi
    • drawable-anydpi (no scaling)
  • like image 43
    LanDenLabs Avatar answered Sep 27 '22 23:09

    LanDenLabs