0

I know about <resources_name>-<qualifier> naming convention for resources in Android and how to use them for screen sizes (e.g. <drawable_xLarge>) or screen densities (e.g. <drawable xhdpi>).

I want to know, how to handle the case of supporting different densities for each screen size variation there is. Ie

<drawable-xlarge>
    <drawable-xhpdi>
    <drawable-hpdi>
    <drawable-mpdi>
    <drawable-lpdi>

<drawable-large>
    <drawable-xhpdi>
    <drawable-hpdi>
    <drawable-mpdi>
    <drawable-lpdi>
...

Can any one enlighten me please? Cheers

Abolfoooud
  • 2,663
  • 2
  • 27
  • 27

2 Answers2

2

This is a very complicated question. There is a very good explanation in the documentation you should check.

http://developer.android.com/guide/practices/screens_support.html

Otherwise, your question is way too open ended.

The specific paragraph you will find in the docs is:

Provide different layouts for different screen sizes

By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes. For example, on a larger screen, you might want to adjust the position and size of some elements to take advantage of the additional screen space, or on a smaller screen, you might need to adjust sizes so that everything can fit on the screen.

The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in layout-xlarge/.

Beginning with Android 3.2 (API level 13), the above size groups are deprecated and you should instead use the swdp configuration qualifier to define the smallest available width required by your layout resources. For example, if your multi-pane tablet layout requires at least 600dp of screen width, you should place it in layout-sw600dp/. Using the new techniques for declaring layout resources is discussed further in the section about Declaring Tablet Layouts for Android 3.2.

Booger
  • 18,579
  • 7
  • 55
  • 72
  • I have read the reference you provided before raising my question. But the only thing I found was an indication of supporting multiple screens, or supporting multiple densities. There is no where to solve my question about different densities for different screens – Abolfoooud May 01 '14 at 12:25
  • The information is in the docs, I included the paragraph in my answer. This is a complicated question, so I suggest you research further if you want to understand this issue better. – Booger May 01 '14 at 13:12
  • I have re-read that particular page many, many times, and still don't fully understand it all. The way Android handles multiple screens if very flexible (and complicated). – Booger May 01 '14 at 15:31
1

There are two approaches to solve this problem.

First

define your drawables like below.

drawable-small-mdpi
drawable-normal-hdpi
drawable-large-hdpi
drawable-xlarge-hldpi

Ref : Screen Compatability issue in android

Second

If you like to provide density wise drawables, following way you can do this.

For Example, if you want to set drawable for smallest width of 600 dp then create directory with name

drawable-sw600dp

as like for 720 dp, create directory with name

drawable-sw720dp

This way you can define density wise drawable directory.

Community
  • 1
  • 1
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93