How Android finds the best matching directory

Android will pick which of the various underlying resource files should be used at runtime, depending on the current configuration. The selection process is as follows:

1. Eliminate any resources whose configuration does not match the current device configuration. For example, if the screen pixel density is 108dpi, this would eliminate only MyApp/res/drawable-port-92dpi/.

MyApp/res/drawable/myimage.png MyApp/res/drawable-en/myimage.png MyApp/res/drawable-port/myimage.png MyApp/res/drawable-port-92dpi/myimage.png

2. Pick the resources with the highest number of matching configurations. For example, if our locale is en-GB and orientation is port, then we have two candidates with one matching configuration each: MyApp/res/drawable-en/ and MyApp/res/drawable-port/. The directory MyApp/res/drawable/ is eliminated because it has zero matching configurations, while the others have one matching configuration.




3. Pick the final matching file based on configuration precedence, which is the order of parameters listed in the table above. That is, it is more important to match the language than the orientation, so we break the tie by picking the language-specific file, MyApp/res/drawable-en/.

MyApp/res/drawable-en/myimage.png MyApp/res/drawable port/myimagc.png

0 0

Post a comment