android-layoutandroid-studio-3.0screen-sizeandroid-layout-weightscreen-density

Which layout qualifier should be used with Android 3.0 or above?


I was using layout normal, large, x-large but it was not working. I found out that Android works on the smallest dp. So I searched and found these two methods for layouts qualifier.

First method is to use layout-mdpi, layout-hdpi, layout-xhdpi, layout-xxhdpi. Second method is to use layout-sw320dp, layout-sw480dp, layout-sw600dp, layout-sw720dp.

Now I am confused about which method is the standard way to use layout-qualifiers? I have searched around Google Docs Screen Density

I am not able to get final decision what to use for layout from the above-mentioned methods


Solution

  • Which layout qualifier (for different screen sizes) you should use does not depend on which Android Studio version you're using. It depends on what you need.

    In your case, if you want to support devices (for different screen sizes) which run on API level 12 or lower, you have to use the legacy size qualifiers (e.g. x-large). If you want to run it on devices using APIs above level 12, you can use the smallest and/or available width qualifier (e.g. w-600dp and sw-600dp respectively). Read more here. All the qualifiers in this paragraph are standardized; it just depends on what you need.

    The qualifiers mdpi, hdpi, and so on are not used as qualifiers for different screen sizes layout, but for resources (in particular, images). This is so that Android can auto-generate versions of your rasterized images to display good graphical qualities for screens with different pixel densities.