Home > front end >  How to fill image in entire screen
How to fill image in entire screen

Time:12-13

I'm writing a simple application and I need to set a photo so that it fills the entire screen. It would look good horizontal, but I've been working on it for over an hour and I still can't. I don't know, or I'm too stupid or this android doesn't like me that much. I tried to use youtube, internet etc. and nothing works the way I want

I would be grateful if someone told me how to do it, or at least give me a path, because. With extra stuff, this photo is 1920x1080 in size

Here is the code what I tried to do:

 <StackLayout>
    <Image Source="wallpaper1.png" Rotation="90 HorizontalOptions="Center" VerticalOptions="Center" Aspect="Fill"></Image>

   
 </StackLayout>

Greetings

CodePudding user response:

You will want to change HorizontalOptions to "CenterAndExpand", and you will want to do the same for VerticalOptions. This will tell the image to expand as much as it can, but it can be limited to elements taking space above it if there are any.

Alternatively, you can put the image in an absolute layout instead of a stack layout and put the following in the Image tag:

<AbsoluteLayout
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand"/>
    <Image
        AbsoluteLayout.LayoutBounds="0,0,1,1"
        AbsoluteLayout.LayoutFlags="All"
        .../>
</AbsoluteLayout>

The above will cause your image to fill the entire screen. The LayoutBounds property tells the image to start at X and Y coordinates of 0. The 1 and 1 property indicate a proportion of how much in the X and Y directions to expand. In this case, it is 100% of the available space.

LayoutFlags="All" allows the bounds to be interpreted that way.

CodePudding user response:

.xaml:

<StackLayout>
        <Image  Source="ddd.png" ></Image>
</StackLayout>

Add this to your MainActivity.cs:

protected override void OnCreate(Bundle savedInstanceState)
{
    ...

    IWindowInsetsController wicController = Window.InsetsController;
    Window.SetDecorFitsSystemWindows(false);
    Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

    if (wicController != null)
    {
       wicController.Hide(WindowInsets.Type.NavigationBars());
    }
           
    this.RequestedOrientation = ScreenOrientation.Landscape;
}
  • Related