Background image different sizes for different size screens

GiorgiGiorgi USMember ✭✭

I want to set background image for the whole page and I have the same image with different dimensions. In an Android project I would put different size images in different folders (mdpi, hdpi, etc) and the system would automatically use the one based on screen size. How can I accomplish the same with Xamarin.Forms?

Answers

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Giorgi said:
    I want to set background image for the whole page and I have the same image with different dimensions. In an Android project I would put different size images in different folders (mdpi, hdpi, etc) and the system would automatically use the one based on screen size. How can I accomplish the same with Xamarin.Forms?

    Xamarin Forms follows the native selection method. It doesn't change. In Xamarin Forms Android project place the images as you have done for Android. Same for iOS, just follow Apple's recommendation of naming the images @2x or @3x.

  • jezhjezh Member, Xamarin Team Xamurai

    Xamarin.Forms is a framework that allows developers to build cross-platform applications for Android, iOS, and Windows. Code and user interface definitions are shared across platforms, but rendered with native controls.
    Xamarin.Forms applications use .NET Standard projects to contain the shared code, and separate application projects to consume the shared code and build the output required for each platform.For example,A Page represents an Activity in Android, a View Controller in iOS, or a Page in the Windows Universal Platform (UWP).

    Besides, from Images in Xamarin.Forms, we see that

    Xamarin.Forms offers a number of different ways to include images in a cross-platform application, allowing for the same image to be used across platforms or for platform-specific images to be specified. Downloaded images are also automatically cached, automating a common coding scenario.
    Application icon and splash screen images are set-up and configured as for non-Xamarin.Forms applications - follow the same guidance used for platform-specific apps.

    So when we want to achieve the same effect as android project in Xamarin.Forms , it follows the same rules as in the native Android or IOS. Just as you said , we can put different size images in different folders (mdpi, hdpi, etc) and the system would automatically use the one based on screen size. For iOS, just follow the rules in IOS.

    For more details, you can check: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows

Sign In or Register to comment.