xaml - 在Xamarin.Forms的图像上方叠加标签,列表和按钮

标签 xaml xamarin xamarin.forms

我要制作一个页面,其中有图片,并且基本上所有其他内容都在图像顶部。

与此类似

enter image description here

XAML代码如下:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Project.Page">
<ScrollView>
    <AbsoluteLayout>
        <Image Source="{Binding ContentImage}}"  Aspect="AspectFill" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1"/>
        <Label Text="{Binding label}" FontSize="15" AbsoluteLayout.LayoutFlags="PositionProportional" AbsoluteLayout.LayoutBounds="0,1,-1,-1" />
    </AbsoluteLayout>

</ScrollView>

到目前为止,我已经知道了。但这仅在右下角具有标签方式,而且我似乎无法使列表或按钮正常工作。我当时想也许只是以图像为背景,但是应该通过按一下按钮或其他方式来改变图像,但我不确定是否可以使用背景图像来做到这一点。

Xamarin.Forms可能会发生这种情况吗?

对不起,如果我的英语不好!这是我的第二语言!

提前致谢!

编辑:我能够使用图像作为背景,并通过单击按钮进行更改。现在,我只需要了解如何实际定位ListView。

最佳答案

我从演示中移动了一些项目,这只是使用AbsoluteLayout和Grid处理它的一种方法

<AbsoluteLayout x:Name="ViewLayout">
    <Image Source="coffee.png" Aspect="AspectFill" AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All" />
    <AbsoluteLayout x:Name="ViewControls" AbsoluteLayout.LayoutBounds="1,1,1,.50" AbsoluteLayout.LayoutFlags="All" BackgroundColor="#66000000" Margin="10,10,10,10">
        <StackLayout Orientation="Vertical" Margin="20,20,20,20" BackgroundColor="Transparent" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="1,1,1,1">
            <Grid Margin="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Label Text="Salted Caramel Mocha Frappuccino" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="2" />
                <Button Text="Extra Shot" BackgroundColor="#77000000" BorderRadius="4" BorderColor="White" BorderWidth="2" TextColor="White" Grid.Row="0" Grid.Column="3" />
                <Button Text="Whipped Cream" BackgroundColor="#77000000" BorderRadius="4" BorderColor="White" BorderWidth="2" TextColor="White" Grid.Row="1" Grid.Column="3" />
            </Grid>
            <Grid Margin="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Button Text="Tall (12oz)" BackgroundColor="#77000000" BorderRadius="4" BorderColor="White" BorderWidth="2" TextColor="White" HorizontalOptions="FillAndExpand" Grid.Column="0" />
                <Button Text="Grande (16oz)" BackgroundColor="#77000000" BorderRadius="4" BorderColor="White" BorderWidth="2" TextColor="White" HorizontalOptions="FillAndExpand" Grid.Column="1" />
                <Button Text="Venti (20oz)" BackgroundColor="#77000000" BorderRadius="4" BorderColor="White" BorderWidth="2" TextColor="White" HorizontalOptions="FillAndExpand" Grid.Column="2" />
            </Grid>
        </StackLayout>
    </AbsoluteLayout>
</AbsoluteLayout>

enter image description here

关于xaml - 在Xamarin.Forms的图像上方叠加标签,列表和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46921938/

相关文章:

android - Xamarin.Android 应用程序上的 Vague Dotfuscator 错误

android - MonoDroid 自定义控件 + 以编程方式填充 ListView

xamarin - NetStandard 库未获得对 VSTS 构建代理的依赖关系

c# - 如何使用 ICommand 在 Xamarin 中停用按钮

Xamarin 表单 : Add Clear Entry

c# - 如何拥有动态 DataTemplateSelector

wpf - 如何使用数据绑定(bind)根据属性值设置 DataGrid 的行背景

c# - 将自定义字体添加到 Windows Phone 8 应用程序

xaml - 如何阻止 Android ScrollViewer 将其自身滚动到其第一个按钮子项

c# - 无法从 WPF 中的另一个元素绑定(bind)到 ZIndex