3

I am new to the concepts of android layouts associated with different screen sizes. I wish to make a different layout for a tab which is of 8" and place it in a "layout-swxxxx" folder. And have another generic layout for tabs bigger than than 8" in "layout" folder.

Here is the configuration of my 8" tablet. Screen size 8.0 inches Resolution 1200 x 1920 pixels (~283 ppi pixel density)

Can anyone tell me how to calculate the "sw", so that i can name my layout folder accordingly.

Also I don't have the physical device with me so its not possible for me to find this value with any code. So request an alternative method.

Thank you in advance.

qualitytest
  • 763
  • 1
  • 10
  • 18

1 Answers1

9

The formula linking dp, pixels and density is as follow :

px = dp * (dpi / 160)

Therefore, in your case,

widthInDp = widthInPx / (dpi / 160)
widthInDp = 1200 / (283 / 160)
widthInDp = ~678dp

So you're gonna want to use a bucket such as sw600dp

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

NSimon
  • 5,212
  • 2
  • 22
  • 36
  • Thank you for the explanation. Using this formula i tried to calculate Width in dp for another tab (1200 x 1920 ~224 ppi). I got the width as ~857. But this tab seems to pick the layout from layout-sw480dp. I do not understand the behavior. Could you please help me understand – qualitytest Apr 19 '16 at 07:21
  • 1
    What you need is to create a layout directory sw857dp (or even sw850dp), so that the device will grab the layouts from there, rather than sw480dp. Remember, sw480dp means "if the device has at least a screen width of 480 AND there isn't a folder closer to the device's actual SW, use sw480dp". – FractalBob Jul 27 '17 at 22:53
  • @FractalBob Using the above calculation, The smallest width of Huawei MediaPad T3 (8 inch tablet) is 533. The device configuration of the device is (600 x 1280 ~240 ppi). This is actually less than 600. How do i make this device to support Tablet layout? – DroidLearner Jan 30 '18 at 12:38