VaaS
VaaS

Reputation: 647

How to find out which drawable resource is used?

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

Answers (6)

Harshid Vasoya
Harshid Vasoya

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

Ajith M A
Ajith M A

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

Hardik Trivedi
Hardik Trivedi

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

MH.
MH.

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:

  • 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.

Upvotes: 7

Pavan
Pavan

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

YumeApps
YumeApps

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

Related Questions