I want to know which drawable resource is used while running the application that is either from ldpi, mdpi, hdpi or xhdpi.
-
[Have a look at this post](http://stackoverflow.com/a/4766229/593709) – Adil Soomro Feb 13 '12 at 07:06
-
I ended up creating an app for that some time ago: https://play.google.com/store/apps/details?id=com.roysolberg.android.developertools – Roy Solberg Sep 11 '12 at 07:42
6 Answers
You should be able to get your device's display properties as described here and subsequently determine what resources are being used at runtime by comparing the result against this list:
- ldpi: Low-density screens; approximately 120dpi.
- mdpi: Medium-densit (on traditional HVGA) screens; approximately 160dpi.
- hdpi: High-density screens; approximately 240dpi.
- xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
- nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
- tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a "primary" density group. It is mostly intended for televisions and most apps shouldn't need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. This qualifier was introduced with API level 13.
From this information you can deduce the following, which might also be relevant for your question:
There is a 3:4:6:8 scaling ratio between the four primary densities (ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi and 24x24 in xhdpi.
You have to first get density of your device.
int density= getResources().getDisplayMetrics().densityDpi;
switch(density)
{
case DisplayMetrics.DENSITY_LOW:
Toast.makeText(context, "LDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_MEDIUM:
Toast.makeText(context, "MDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_HIGH:
Toast.makeText(context, "HDPI", Toast.LENGTH_SHORT).show();
break;
case DisplayMetrics.DENSITY_XHIGH:
Toast.makeText(context, "XHDPI", Toast.LENGTH_SHORT).show();
break;
}

- 5,701
- 4
- 37
- 50
We can determine this by knowing the screen density of the device.
getResources().getDisplayMetrics().densityDpi
It will be either DENSITY_LOW, DENSITY_MEDIUM, or DENSITY_HIGH.

- 711
- 2
- 6
- 17
This isn't an exact answer, but have you taken a look at: http://developer.android.com/guide/practices/screens_support.html
ldpi: Resources for low-density (ldpi) screens (~120dpi)
mdpi: Resources for medium-density (mdpi) screens (~160dpi)
hdpi: Resources for high-density (hdpi) screens (~240dpi)
xhdpi: Resources for extra high-density (xhdpi) screens (~320dpi)
These are general guidelines, and it won't be perfect but it's a pretty good start.

- 118
- 8
Open xml file from layout folder. In bottom you will find graphical layout tab. There you will be able to see graphical view of your xml file. For top left corner select different-different resolution for which you want to test drawable. It will refresh the view accordingly.

- 5,677
- 5
- 31
- 51
Here is a sample code to find that. Simply put some different drawables in different folders and check which image is picked up by the device automatically.

- 3,838
- 3
- 32
- 55