【问题标题】:How to add background image to grid layout in xamarin forms?如何在 xamarin 表单中将背景图像添加到网格布局?
【发布时间】:2019-05-01 11:15:30
【问题描述】:

我有四行两列。我需要将背景图像显示为全网格。请提供解决方案。我在内容页面链接中提到了这个创建背景图像:Xamarin Forms - how to add background image to a content page .但是如何将背景图像设置为网格布局。

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    只需将图像添加到第一行和第一列,设置 ColumnSpan 和 RowSpan 以覆盖整个网格并将 Aspect 设置为 AdjustFit。

    然后您将要添加的其他项目添加到网格中。

    一个网格单元格可以容纳多个元素,但请记住,单元格中的最后一项将位于之前添加的项之上。

    例如:

    <Grid>
        <Image>
        <Button>
    </Grid>
    

    该按钮是订单中的最后一项,因此它将成为最顶部的一项并且可以点击。如果您先有按钮,然后有图像,则图像会覆盖按钮,因此无法点击。

    【讨论】:

    • 由于分辨率问题我不能使用绝对布局。
    【解决方案2】:

    您将不得不在这里做一些AbsoluteLayout 诡计:

    <AbsoluteLayout>
    <Image  AbsoluteLayout.LayoutBounds="0, 0, 1.0, 1.0" AbsoluteLayout.LayoutFlags="All" InputTransparent="true" Source="Your_Image" Aspect="AspectFill" />
    <!--Your Grid Here-->
    <Grid AbsoluteLayout.LayoutFlags="All" BackgroundColor="Transparent" AbsoluteLayout.LayoutBounds="0, 0, 1.0, 1.0" />
    <AbsoluteLayout>
    

    请注意将图像首先放置在绝对布局中,以便它位于后面, 并将其输入设置为透明,这样它就不会发生任何点击事件。

    【讨论】:

      猜你喜欢
      • 2012-03-22
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多