3

I just want a layout folder for 21 inch screen.I have sw600dp for 7 inch tablet and sw720dp layout folder for 10 inch tablet.how i specify folder for hp slate 21 inch tablet in android?thanks in advance

mmBs
  • 8,421
  • 6
  • 38
  • 46
Sharad Mhaske
  • 1,103
  • 9
  • 19

3 Answers3

0

If you know the resolution (or roughly) of the screen you can work out the dp folder you'll need.

px = dp * (dpi / 160)
TMH
  • 6,096
  • 7
  • 51
  • 88
0

See http://developer.android.com/guide/topics/resources/providing-resources.html . sw720dp means smallest width 720dp, so this will be used by all devices having a smallest width of 720dp or more.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
  • i dont want sw720dp for 21 inch tablet – Sharad Mhaske Oct 16 '13 at 12:53
  • sw720dp does not mean you get a layout thats 720dp wide. Layouts in Android always adopt to the available screen size. It's just that you can provide a different layout here for large screens and provide another one for handheld devices in the default layout folder. – Ridcully Oct 16 '13 at 18:19
  • so how i provide layout for 21 inch screen? – Sharad Mhaske Oct 17 '13 at 03:46
  • By putting the layout in the layout-sw720dp folder. – Ridcully Oct 17 '13 at 08:36
  • i have layout folder layout-sw720 for 10 inch tablet as i have very big layout for 21 inch screen which may not look good on 10 inch screen. – Sharad Mhaske Oct 17 '13 at 09:06
  • You don't get it, do you? Android stretches each layout so it fills the available space. You can run the same app with the same layout on a 3.5'' screen as well as on a 21'' screen and it will always fill up all the screen space. The different layout- folders are only there if you want to provide a separate layout, e.g. with two columns instead of one, for larger screens. – Ridcully Oct 17 '13 at 16:06
  • what about the dimensions of diff view?i dont want same dimension on 21 inch screen.i know layout will streches but i dont want that right? – Sharad Mhaske Oct 18 '13 at 03:38
  • Well, you can go with a layout-w1024dp and replace the 1024 by the dp-value of the 21'' screen. To calculate that value you'll need the device's resolution as well as the size. According to the link you posted, the device has a resolution of 1920 by 1080 pixels on a 21.5'' 16:9 screen. This means it has a width of 18.73'' which gives us a resolution of (only) 102dpi, and thus, according to http://developer.android.com/guide/practices/screens_support.html would use the layout-ldpi! – Ridcully Oct 18 '13 at 11:32
  • :their is nothing like layout-w1024dp as it gives error.i think google has not specified the layout folder for 21 inch screen specifically. – Sharad Mhaske Feb 27 '14 at 07:34
  • @Ridcully. I too have the same problem. Could you please provide me a solution. – Balaji Dhanasekar Oct 21 '14 at 11:05
0

Just add the below code in somewhere your Activity and run the application in that device, you will get the value of smallestWidthDp. suppose if you get it 800 then you need to create layout folder named layout-sw800dp

Configuration mConfig = this.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= 13) {
        int smallest_width_dp_value = mConfig.smallestScreenWidthDp;
                    Log.e("smallestWidthDp",smallest_width_dp_value+"");
    }
Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57