Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to know (programmatically) which resources folder is used based on screen density/size

Is there a way to know exactly which layout (and other resources) are chosen by Android during runtime based on screen density and size when supporting multiple screens?

I need to know the folder's name.

EDIT:

I need to know the folder's name programmatically.

like image 696
Seraphim's Avatar asked Jun 17 '13 21:06

Seraphim's


1 Answers

If you're just doing this for debugging purposes, I'd recommend doing something like this: For each qualifier that you have a layout/drawable for, have a values folder with the same qualifier (e.g. if you have a layout-hdpi, also have a values-hdpi to match). Add a strings.xml for each of these folders, and define a string:

In values-hdpi:

<string name="folder_name">hdpi</string>

In values-xhdpi:

<string name="folder_name">xhdpi</string>

Then just resolve the string when you need it, and it will tell you which folder was selected.

like image 80
Kevin Coppock Avatar answered Sep 20 '22 19:09

Kevin Coppock