Search code examples
androidlayoutresolution

How to find out which layout a particular screen fits in?


In Android development I see there are many categories for each layout such as:

  • res/layout-small/my_layout.xml
  • res/layout/my_layout.xml
  • res/layout-large/my_layout.xml
  • res/layout-xlarge/my_layout.xml

If I have a tablet with a resolution of 1920x1200 how do I know which layout does it belong to? What if I have a device with a resolution of 480x640?

Ultimately my question is, what is the process in determining the category an arbitrary resolution will fall in it?


Solution

  • It is explained here in detail. https://developer.android.com/guide/practices/screens_support.html

    But, in a nutshell, the layouts are selected based on the density independent pixels (dp) and dp is calculated based on the resolution and the actual size of the screen. 160 dpi was taken as the reference to dp and it is calculated like the following for the screens that have other resolution.

    dp = px * 160 / dpi

    and the selection of the layout is done based on these rules:

    xlarge screens are at least 960dp x 720dp

    large screens are at least 640dp x 480dp

    normal screens are at least 470dp x 320dp

    small screens are at least 426dp x 320dp