RK_05
RK_05

Reputation: 23

Images in mdpi and ldpi in Android

In my Android app, i have kept some of the images in "mdpi" and remaining in "ldpi". Then also my app is working properly on various devices(Virtual as well as Mobile). Aren't the images suppose to be fetched w.r.t the Device's Resolution. How come they are displayed???

Upvotes: 2

Views: 338

Answers (4)

Harpreet
Harpreet

Reputation: 3070

Scenario is as below:

Layouts:-

res/layout/my_layout.xml             // layout for normal screen size ("default") (320 * 480)
res/layout-small/my_layout.xml       // layout for small screen size (240 * 320)
res/layout-large/my_layout.xml       // layout for large screen size (480 * 800/854)
res/layout-xlarge/my_layout.xml      // layout for extra large screen size (720/800 * 1280)

Drawables:-

res/drawable-mdpi/my_icon.png        // bitmap for medium density, used by layout-small & layout
res/drawable-hdpi/my_icon.png        // bitmap for high density, used by layout-large
res/drawable-xhdpi/my_icon.png       // bitmap for xtra-high density, used by layout-xlarge

Hope it help. If have any confusion, do ask. Please do also read once Screens Support APIs

Thanks.

Upvotes: 0

user1969053
user1969053

Reputation: 1760

By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device.

For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.

The configuration qualifiers you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high). For example, bitmaps for high-density screens should go in res/drawable-hdpi.

For more intimation regarding screens, you should refer this.

Upvotes: 1

Anup Cowkur
Anup Cowkur

Reputation: 20553

Android has a very specific algorithm to select the correct drawable. Here's what it looks like:

Android drawable selection

It is explained in much detail here:

http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93561

mdpi and ldpi are overrides. If android finds a drawable by the name its looking for it will use it, however if multiple images exist at different resolutions it will pick the closest one.

Upvotes: 1

Related Questions