DefZep
DefZep

Reputation: 153

Targeting different screen sizes in Android with values-swdp

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);

Upvotes: 3

Views: 4552

Answers (2)

Blundell
Blundell

Reputation: 76468

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

Upvotes: 4

ScanBizCards
ScanBizCards

Reputation: 11

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

Upvotes: 1

Related Questions