Reputation: 647
I want to know which drawable resource is used while running the application that is either from ldpi, mdpi, hdpi or xhdpi.
Upvotes: 13
Views: 7442
Reputation: 5721
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;
}
Upvotes: 6
Reputation: 5348
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.
http://droidschools.com/archives/63
Upvotes: 0
Reputation: 6092
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.
Upvotes: 1
Reputation: 45493
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:
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.
Upvotes: 7
Reputation: 721
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.
Upvotes: 4
Reputation: 118
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.
Upvotes: 1