首页 > 解决方案 > 如何在 XML 中叠加两个图像?

问题描述

我想插入一个八角形的图像。所以我想将八角形(具有透明背景)叠加到图像上。这怎么可能?

我有一个简单网格中的图像,但我不知道如何在其上叠加八角形

我有这个 xml 代码:

<Grid ColumnSpacing="0" RowSpacing="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="AUTO"/>
            <RowDefinition Height="AUTO"/>
            <RowDefinition Height="AUTO"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="AUTO"/>
         </Grid.RowDefinitions>
        <Image Aspect="AspectFill" Source="LogoConRegalo.png"/>
        <Image x:Name="ProfilePicture" HeightRequest="100" HorizontalOptions="Center" Source="Profile.png" TranslationY="50" VerticalOptions="End"/>

使用建议的解决方案: 在此处输入图像描述

标签: xmlxamarin.forms

解决方案


你想达到如下截图的结果吗?

在此处输入图像描述

这是您的布局中的两个图像。

锋利的.jpg

在此处输入图像描述

图像.jpg

在此处输入图像描述

这是代码

<StackLayout>
        <Grid ColumnSpacing="0" RowSpacing="0">
            <StackLayout HorizontalOptions="CenterAndExpand"   VerticalOptions="CenterAndExpand" Padding="0">
                <Image Aspect="AspectFit" Source="sharp.jpg" HorizontalOptions="Center" VerticalOptions="Center" />
            </StackLayout>
            <StackLayout HorizontalOptions="CenterAndExpand"   VerticalOptions="CenterAndExpand" Padding="10">
                <Image HorizontalOptions="Center" VerticalOptions="Center" Source="image.jpg" Aspect="AspectFit"  />
            </StackLayout>
        </Grid>
    </StackLayout>

推荐阅读