如何用图像填充StackLayout

问题描述

我想为导航面板的标题部分提供如下背景图片

enter image description here

我目前有一张图片,可以在StackLayout中显示个人资料图片。代替将BackgroundColor属性设置为StackLayout标签,如何添加背景图像?

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

解决方法

您需要从Stacklayout切换到允许其视图重叠的内容,例如Grid或Absolute布局。

要使用网格,只需将图像和内容放在同一行中即可

<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>

结果:

example_image

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...