Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know smallest width (sw) of an android device?

I have 4 different devices:

  1. Asus tablet, screensize 7"
  2. Lenovo tablet, screensize 7"
  3. HTC mobile phone, screensize 5"
  4. HTC mobile phone, screensize 4.7"

I want to know the smallest width (sw) of my device to make a support layout for it.

I want to make a resource folder like "layout-sw600dp" but I don't know the value of the smallest width (sw).

I tried to print the sw using this code:

DisplayMetrics metrics = getResources().getDisplayMetrics();
Log.i("Density", ""+metrics.densityDpi);

but i don't know if this is the correct value.

How do I find the smallest width (sw)?

like image 829
user2955394 Avatar asked Sep 04 '25 16:09

user2955394


2 Answers

Best solution for min API 13 and above:

Configuration config = getResources().getConfiguration();
config.smallestScreenWidthDp

The last line return the SW value in dp !

Source google : http://android-developers.blogspot.fr/2011/07/new-tools-for-managing-screen-sizes.html

like image 144
Tobliug Avatar answered Sep 07 '25 17:09

Tobliug


Here is an another easy way .

You can check the Smallest Width of the Device from Developer Options (In Android Studio Emulator & It's not found in my Real Device) .

enter image description here

like image 38
Don Chakkappan Avatar answered Sep 07 '25 17:09

Don Chakkappan