maintaining screen density independence

PawelBialekPawelBialek USMember
edited May 2015 in Xamarin.Forms

Hi!

I have a question about SDI in regards to both Android and iOS.
I have a Xamarin.Forms project with iOS and Android subprojects in them, however none of the platforms seem to respect SDI rules.
By that I mean I would like to the proportions of icons and images remain the same in relation to screen size of the device the app is running on.
Instead it seems Xamarin does everything to keep the icons sized equally so that when I look at the app on a device and a tablet the icons are the same if I measured them with a ruler.

On Android I am using Nexus 5 and Nexus 7 for comparison - the resource don't even scale, not mentioning using different resource resolutions (I am supplying hdpi, xhdpi & xxhdpi resource resolutions from google material design repository).

On iOS I have created the resources using this icon generator from the Android's icons above.
I am testing with iOS 4 emulator and iPad 2 emulator.

In both cases the tablet/iPad displays my app with very small icons / images.
Seems none of the platforms respect SDI with my project though I have followed the tips from xamarin android resource tips page
& how to work with images in Xamarin.Forms page including using FileImageSource with build action AndroidResource / BundleResource such as

new FileImageSource () { File = "ic_pause_circle_outline_white_48dp" };

I am also having a similar issue but with fonts.
I use for example Device.GetNamedSize (NamedSize.Medium, typeof(Label)); but for tablets / iPad the font doesn't get properly enlarged.
Is this is how it ought to be ?

Thanks for explanation,

regards,

Pawel

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Xamarin.Forms doesn't handle this any differently than any of the native platform SDKs. You can supply multiple versions of images for different pixel densities, but their physical appearance should be about the same on any screen unless you make the image view that hosts them stretch. You can do that in Xamarin.Forms using the Aspect property of the Image control.

    Just to sanity check, are you sure you're putting the images in the right place with the right names? On iOS that means "Foo.png", "[email protected]", and "[email protected]" (for iPhone 6 Plus). For android that means all variants have the same name but go in different directories (drawable-mdpi, drawable-hdpi, etc.). If you don't follow those conventions then it won't do the right thing. I know you said you generated different resolutions, but it wasn't clear that you put them in the right place. It is unusual to have the "48p" as part of the image name so that just makes me a bit suspicious.

    I am also having a similar issue but with fonts.
    I use for example Device.GetNamedSize (NamedSize.Medium, typeof(Label)); but for tablets / iPad the font doesn't get properly enlarged.

    The worst thing you can do to support iPad is to just magnify your iPhone app. If that's what you want then you may as well just ship an iPhone-only app and let the OS zoom it on iPad. If you want to support iPad properly you should actually design a good UI for a tablet, and you can use Device.Idiom to detect whether you're running on a tablet or a phone.

Sign In or Register to comment.