layout-sw600dp values-sw600dp Android example of use

Why the app selects data from basic layout folder if smallest width is higher then the number in folder name?
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen – dot per inch (pixel per inch) is 480 pixel it is wery important number!

  1. App selects smallest dimension of screen. In our case 900 px
    Medium screen have 160 dpi (The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a “medium” density screen.).
  2. App calculate ratio 480 / 160 = 3 (The conversion of dp units to screen pixels: px = dp * (dpi / 160))
  3. App calculate smallest dimesnion of screen in dp 900 / 3 = 300 dip or dp (density independed pixel).
  4. App selects data from basic values and layout folder because sw600dp is greater than 300dp.

In our case smallest dimension of screen must be at least 1800 real – physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.

Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800×1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.

This entry was posted in Android Examples Code and tagged . Bookmark the permalink.

Comments are closed.