简体   繁体   English

如何用图像填充 Stacklayout

[英]How to Fill Stacklayout with Image

I want to have a background image like the following for the header section of my navigation panel我想为导航面板的 header 部分提供如下背景图像

在此处输入图像描述

I currently have an image to display the profile picture in a StackLayout.我目前有一张图片可以在 StackLayout 中显示个人资料图片。 Instead of setting the BackgroundColor property to the StackLayout tag how can I add a background image?除了将 BackgroundColor 属性设置为 StackLayout 标记外,如何添加背景图像?

<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.您需要从 Stacklayout 切换到允许其视图重叠的东西,例如 Grid 或 Absolute 布局。

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:结果:

示例图像 :

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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