【问题标题】:Overlay label, list and a button on top of an image on Xamarin.Forms在 Xamarin.Forms 上的图像顶部覆盖标签、列表和按钮
【发布时间】:2017-10-25 00:16:07
【问题描述】:

我想制作一个页面,其中有一张图片,基本上是图片顶部页面上的所有其他内容。

类似的东西

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。

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    我从演示中移动了一些项目,这只是使用 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>
    

    【讨论】:

    • 谢谢!这看起来就像一个魅力。现在我只是想知道在这个布局中添加一个列表视图是否会类似地工作?
    • 还有没有办法让列表项像图片一样水平显示?
    • @FrostZone ListView 是严格垂直的,您应该查看CarouselView 以便对控件和视图进行左右分页
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多