简体   繁体   中英

How to Fill Stacklayout with Image

I want to have a background image like the following for the header section of my navigation panel

在此处输入图像描述

I currently have an image to display the profile picture in a StackLayout. Instead of setting the BackgroundColor property to the StackLayout tag how can I add a background image?

<StackLayout>
     <Image Source="profile.png" WidthRequest="75" HeightRequest="75" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</Stacklayout>

You'll need to switch from Stacklayout to a something that allows it's views to overlap, like a Grid or Absolute layout.

To use a grid, simply put your image and your content in the same row:

<Grid>
    <Image Grid.Row="0"
           Aspect="AspectFill"
           Source="airplane" />
    <Label Grid.Row="0"
           FontAttributes="Bold"
           FontSize="Large"
           HorizontalOptions="Center"
           Text="Welcome to Xamarin.Forms!"
           VerticalOptions="CenterAndExpand" />
</Grid>

Result:

示例图像 :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM