【问题标题】:How to set Background Image in Content View in Xamarin如何在 Xamarin 的内容视图中设置背景图像
【发布时间】:2018-03-28 08:45:17
【问题描述】:

我有一个 ContentView,我需要在其中设置背景图像。ContentPage 有“BackgroundImage”属性,在 ContentView 中做什么?在 xamarin 中是否可以在 ContentView 中设置背景图像?

【问题讨论】:

  • 我认为您需要在ContentViewContent 内添加一个Image 并使用RelativeLayoutAbsoluteLayout 才能使其成为背景。跨度>
  • 通过使用 AbsoluteLayout 来做到这一点谢谢!!@PaulKaram
  • 很高兴我能提供帮助。 @Jolly,如果您发布自己的答案并将其选择为已接受,那就太好了,以免像这样打开这个问题。

标签: xaml xamarin.forms


【解决方案1】:

在 ContentView 中使用 AbsoluteLayout 并将 Image 与其他控件放在 AbsoluteLayout 中。它可以工作!!

 <ContentView.Content>
    <AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
        <Image Source="abc.png" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" Aspect="AspectFill"/>
        <ScrollView AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
            <Grid>
                ......
                ......
            </Grid>
        </ScrollView>
    </AbsoluteLayout>
</ContentView.Content>

【讨论】:

  • 图片文件要放在哪里?
  • @alvarogalia 在 Xamarin ContentView 的背景中。现在已经排序了。
  • 这也适用于显示覆盖整个页面的背景。只需简单地将 Image 替换为 BoxView:&lt;BoxView AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" Color="#4B000000" VerticalOptions="FillAndExpand" InputTransparent="True" /&gt;
猜你喜欢
  • 2021-12-04
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-25
相关资源
最近更新 更多