3

I'm running my app from SDK directly on my phone connected with the computer. Is there any way to determine (using the SDK tools) which dpi drawables folder is actually used to display specific png file in the app?

Edit: To make it clear. I figured myself how to get this information using other methods: 1. putting different files under the same names in different dpi folders 2. write w short piece of code to check it programmatically The real question now is: can I get this information directly in SDK (DDMS or Hierarchy Viewer)?

Izydorr
  • 1,926
  • 3
  • 23
  • 40

3 Answers3

3

You cannot find which drawable folder is being used But you can able to find which Density is used.

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

then you can use metrics.densityDpi to find which DPI is used. it will be DENSITY_DEFAULT, DENSITY_HIGH, DENSITY_LOW, DENSITY_MEDIUM, etc. you can compare and find out.

If it is DENSITY_HIGH - drawable-hdpi DENSITY_LOW = drawable-ldpi DENSITY_MEDIUM - drawable-mdpi

See here for Documentation http://developer.android.com/reference/android/util/DisplayMetrics.html

Vivek Khandelwal
  • 7,829
  • 3
  • 25
  • 40
  • This won't always necessarily be true... For example, the original Nexus 7 is TVDPI... The recommendation is not to provide TVDPI resources but to provide normal ldpi, mdpi, hdpi, and xhdpi resource and let the Android OS choose which folder to pull from and scale them accordingly – Justin Aug 10 '13 at 05:09
0

you don't have to know about this. In every drawable-* folder you put your resource with the same name, and than android will choose what drawable have to be shown.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • I know this but I wantto check if the graphic file I can see on the screen is really the one I think should be used. Of course I can check it putting different looking files under the same names in different dpi folders but maybe there's some smarter way to achieve this. – Izydorr Mar 14 '12 at 10:36
  • well android load the resources on a screen basis. So if your screen is hdpi, android will load resources in the hdpi folder. – Blackbelt Mar 14 '12 at 10:38
  • True. So is this information displayed somewhere in DDMS or Hierarchy Viewer or do I have to check it using "tricks" like "fake" images or doing a programmatic test? – Izydorr Mar 14 '12 at 10:45
0

You may try adding different graphics with the same name. By this you may know which folder's graphics your phone is using.

Or check programmatically what screen type is your device (hdp, mdpi, ldpi) and then the respective drawable folder will be used automatically.

Community
  • 1
  • 1
waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • Yes, I know all these options. I just thougt that SDK can give me that information in DDMS or Hierarchy Viewer. – Izydorr Mar 14 '12 at 10:44