3

I know I've gotten this to work on projects before, but for whatever reason, when I try to put dimensions into 'values-sw360dp', screens with a width >= 360dp aren't picking up on those dimens, they're reverting back to the regular 'values' folder. Any ideas why? If you need more information, feel free to ask.

Thank you for your time.

Edit: method for getting screen resolution: (Bionic came out to 360x640dp)

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Log.d("Screen width(px)", width+","+height);

float density = getResources().getDisplayMetrics().density;
Log.d("Screen density", density+"");

float widthDp = width / density;
float heightDp = height / density;
Log.d("Screen width(dp)", widthDp+","+heightDp);
DefZep
  • 153
  • 2
  • 11
  • So what phone / emulator / screen size isn't picking up the correct values bucket? – Blundell Jun 21 '12 at 19:12
  • Droid Bionic. (360x640dp) I've got the default "values" folder, and a "values-sw360dp" folder... Bionic is using the dimensions in the default "values" folder. – DefZep Jun 21 '12 at 19:16

2 Answers2

4

I also think your maths is off.

Nexus one is 480 x 800 pixels with a 3.7inch screen this gives a DPI of 252dip.

You can use this website to calculate density: dpi

or do it manually.

This explains density buckets: list-of-android-devices-with-pixel-density-buckets.

So for the Google Nexus One to pick it up, you would have

/values-sw530dp/

By the way, do you declare

android:minSdkVersion="7" in your manifest, as what your attempting won't work on Android 1.5 (if your using old emulators or something).

Pang
  • 9,564
  • 146
  • 81
  • 122
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • This could be an interesting read for you as well: http://stackoverflow.com/questions/9111206/issue-with-dp-calculation-on-7-tablet-7-tablet-emulator – Blundell Jun 21 '12 at 19:47
  • Where did you get sw530dip? I think it should be "width / scale factor" so it's "480 / ~(252 / 160)" = sw320dp. Also from docs "320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc)". – Evmorov Jul 11 '14 at 18:50
1

I think your math is off:

According to Wikipedia, the display is Display 4.3-inch 960 × 540 px qHD at 256 ppi

160/256 = 0.625

0.625*540 = 337.5

Try values-sw335dp and see if that works

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
  • I've tried using ridiculously low values such as 100dp, but then even my Nexus One doesn't pick it up. Here's the info I got from a WindowManager check & Log statement: 540x960 (raw px), 1.5 density = 360x640 in dp. Maybe I did something wrong with the conversion or a wrong value from getResources().getDisplayMetrics().density? – DefZep Jun 21 '12 at 19:31
  • Try spitting out the value you receive from DisplayMetrics.density, I'm curious to see what that gives you. Also, make sure you are targeting at least level 13. – ScanBizCards Jun 21 '12 at 20:12