0

I am pretty much confused right now. I tried making different images and put them in appropriate folder(xhdpi,ldpi) but my app is not working for every device type from 2.7" to 10". So I decided to make different layouts for different screen sizes. I am getting device size in inches from this code-

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
double x = Math.pow(dm.widthPixels/dm.xdpi,2);
double y = Math.pow(dm.heightPixels/dm.ydpi,2);
double screenInches = Math.sqrt(x+y);
Log.d("debug","Screen inches : " + screenInches);

Now all I want that is if the device size is of around lets say 2.7" my app start using layouts from custom folder. Is that possible?

Mihir
  • 2,064
  • 2
  • 21
  • 28

1 Answers1

0

You can include tags on widgets at one of your layout file with different qualifiers and check those tags on runtime.

layout-large/layout1.xml:
     <Button
    android:id="@+id/btn1"
    ...
    android:tag="large" />

layout-small/layout1.xml:
     <Button
    android:id="@+id/btn1"
    ...
    android:tag="small" />

Check them at runtime:

findViewById(R.id.btn1).getTag().toString()
IronBlossom
  • 3,898
  • 3
  • 35
  • 42