如何解决如何用图像填充StackLayout
我想为导航面板的标题部分提供如下背景图片
我目前有一张图片,可以在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>
结果: