0
votes

I really confused about android qualifiers.

I want to create custom design for RatingBar. So I created rating_bar.xml file and put it to drawable folder. Here is the source:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background" android:drawable="@drawable/star_off"/>
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/star_on"/>
    <item android:id="@android:id/progress" android:drawable="@drawable/star_on"/>
</layer-list>

I have star design for xhdpi displays only. I thought that if I put star_on and star_off images to drawable-xhdpi folder than everything will automatically be resized for all different densities (mdpi and hdpi). Yep, it resized, but I got some artifacts for hdpi and mdpi. The same as here: Android custom RatingBar image artifacts I tried solutions that were described there, but nothing helped me. On xhdpi devices I have no artifacts, but on mdpi and hdpi devices there are artifacts.

Then I decided to put star_on and star_off images to drawable-nodpi folder. So I got good result without any artifacts for xhdpi and hdpi screens, but for mdpi screen images were too big.

Then I decided to copy star_on and star_off images to drawable-mdpi folder and reduce images size. It also didn't help.

Then I put big star images to xhdpi and hdpi folders, and small star images to mdpi folder. I thought that if I run my app on mdpi device images from drawable-mdpi will be chosen. But it seems like Android choose images from hdpi or from xhdpi folder and scale them automatically for mdpi screen because I have artifacts again. I also tried to put small images to drawable folder. It also didn't help.

So how Android choose resources? I thought if I have resources шт drawable, drawable-mdpi, drawable-hdpi and drawable-xhdpi than Android try to find resource in folder with same density as device has. And if there are no such resource than it takes from drawable folder.

2

2 Answers

4
votes

This Developers guide part explains what you exactly need i guess. It demonstrates with an example:

To demonstrate how Android selects an alternative resource, assume the following drawable directories each contain different versions of the same images:

drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/

And assume the following is the device configuration:

Locale = en-GB 
Screen orientation = port 
Screen pixel density = hdpi 
Touchscreen type = notouch 
Primary text input method = 12key

By comparing the device configuration to the available alternative resources, Android selects drawables from

drawable-en-port

There is also a selection diagram describing how android selects qualifiers.

2
votes

android choose resources from drawable folders according to dpi

there are four screen densities

  1. ldpi
  2. mdpi
  3. hdpi
  4. xhdpi

four screen sizes

layout-small
layout-nomal
layout-large
layout-xlarge

small screen size = 2.2" - 2.7" (approx)

normal screen size = 3.0" - 4.7" (approx)

large screen size = 5" - 7" (approx)

xlarge screen size = 7"> (approx)

ldpi = 120dpi

mdpi = 160dpi

hdpi 240dpi

xhdpi = 320dpi

create your avd according to these densities and screen sizes then check the result