【问题标题】:How do I add a BackgroundImage to a ListView in Xamarin Forms?如何将 BackgroundImage 添加到 Xamarin Forms 中的 ListView?
【发布时间】:2017-06-13 14:58:19
【问题描述】:

我知道 ListView 类没有名为 BackgroundImage 的属性 - 只有 BackgroundColor 属性,但这不是我想要的。有没有一种方法可以将背景图像添加到 ListView 中,这样当我滚动图像时,图像会保持原位,而当您滚动时,图块只会在图像上“移动”。

将图像添加到ContentPage 也不起作用,因为 ListView 只是覆盖它。

【问题讨论】:

  • 您可以尝试使列表视图和列表视图项的背景透明,并将图像放在列表视图后面。

标签: c# xaml xamarin xamarin.forms background-image


【解决方案1】:

您的帖子非常好,您只是错过了 Source 属性上的双引号

将您的ListViewBackgroundColor 设置为Transparent

<RelativeLayout>
    <Image Source="background.png" 
        BackgroundColor="Transparent" 
        VerticalOptions="CenterAndExpand" 
        HorizontalOptions="CenterAndExpand"/>
    <ListView x:Name="listView" 
        VerticalOptions="CenterAndExpand"
        HorizontalOptions="CenterAndExpand"
        BackgroundColor="Transparent"
              ItemTapped="OnItemTapped"
              ItemsSource="{Binding .}" />
</RelativeLayout>

【讨论】:

  • @LeMotJuiced 设置背景颜色应该对 ListView 滚动没有影响,您应该在问题和代码中发布一个新问题
  • 不是设置背景色,而是在RelativeLayout里面放了一个ListView。
  • @LeMotJuiced 这个问题是关于背景图片的,我用过RelativeLayouts,它们很好,这取决于容器等......你应该用你的问题和代码发布一个新问题
  • 目前我只是放弃了整个想法。我刚刚发布了评论,以防您知道快速修复。我投了你一票,伙计,不要对我苛刻!
猜你喜欢
  • 2021-10-23
  • 1970-01-01
  • 1970-01-01
  • 2020-02-10
  • 1970-01-01
  • 2015-05-11
  • 2017-01-05
  • 2017-01-21
  • 1970-01-01
相关资源
最近更新 更多