onefootswill
onefootswill

Reputation: 4107

Multiple Device Densities and Xamarin Android

I'm struggling with a custom control and getting it to render properly on different devices. I have a map (a map of a state) which I am rendering on the screen.

My drawables looks like this:
drawable
drawable-sw320dp
drawable-sw360dp

The problem is, there are 2 phones I have access to (my Samsung Galaxy 6 and my wife's Sony XPeria Compact).

2 very different phones. They both use the map which I put in the 360 folder. But the map is far too big for the Sony. Even if I drop 360 to 350, both phones use the 350 folder.

A few more stats about the phones:
Samsung
Width in Pixels: 1440
Height in Pixels: 2560
Width in Dp: 360
Height in Dp: 640

Sony
Width in Pixels: 720
Height in Pixels: 1184
Width in Dp: 360
Height in Dp: 592

How can I structure my drawable folders, such that the Sony uses the smaller map png?

Upvotes: 2

Views: 469

Answers (2)

Robbit
Robbit

Reputation: 4358

You can refer to this.

How can I structure my drawable folders, such that the Sony uses the smaller map png?

Yes, you need a smaller map picture for the Sony, and a bigger map for Samsung.

You can use Resources.DisplayMetrics.Ydpi and Resources.DisplayMetrics.Xdpi to get value of dpi in your two phones. And refer to the quote in @hichame.yessou's answer to choose which folder to put bigger map, which folder to put smaller map.

If you don't have two picture, you can adaptive the UI programmatically, please refer to TypedValue.applyDimension

Upvotes: 1

Hichame Yessou
Hichame Yessou

Reputation: 2718

I would use configuration qualifiers, structuring your Resources folder like this and defining every configuration folder:

drawable-ldpi Resources folder for low-density (ldpi) screens (~120dpi).
drawable-mdpi Resources folder for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
drawable-hdpi Resources folder for high-density (hdpi) screens (~240dpi).
drawable-xhdpi Resources folder for extra-high-density (xhdpi) screens (~320dpi).
drawable-xxhdpi Resources folder for extra-extra-high-density (xxhdpi) screens (~480dpi).
drawable-xxxhdpi Resources folder for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi).

Keeping in mind that the ratio for the assets between these configurations is:

ldpi | mdpi | hdpi | xhdpi | xxhdpi | xxxhdpi
0.75 | 1    | 1.5  | 2     | 3      | 4

Upvotes: 3

Related Questions