【发布时间】:2017-11-20 17:14:37
【问题描述】:
我正在尝试为整个网格设置背景图像,而不仅仅是单行/列。设置BackgroundImage= "image.jpg" 可以在 android 上运行,但在 iOS 上它会显得拉伸。我附上了来自 android 端的屏幕截图,以便更清楚地了解它应该是怎样的。
代码
<?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="LoyaltyWorx.GridMenu"
Title="Main Menu"
>
<Grid>
<Image Source="grid.jpg"></Image>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Label Text="Cards" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="0" Grid.Column="0" BackgroundColor="#1481BA" Opacity="0.5" x:Name="CardTile"/>
<Label Text="Transactions" TextColor="Black" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="0" Grid.Column="1" BackgroundColor="#ede890" Opacity="0.5" x:Name="TransactionTile"/>
<Label Text="Promotions" TextColor="White" FontSize="30" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="1" Grid.Column="0" BackgroundColor="#1481BA" Grid.ColumnSpan="2" Opacity="0.7" x:Name="PromoTile"/>
<Label Text="Settings" TextColor="Black" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="2" Grid.Column="0" BackgroundColor="#ede890" Opacity="0.5" x:Name="SettingsTile" />
<Label Text="My Profile" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Grid.Row="2" Grid.Column="1" BackgroundColor="#1481BA" Opacity="0.7" x:Name="ProfileTile"/>
</Grid>
</ContentPage>
正如您在上面的代码中看到的,我尝试添加,但所做的只是将图像包含在“卡片”块中。如何将其设置在整个网格的后面?
【问题讨论】:
-
如何将图像标签添加到这些属性
以适应网格大小? -
试过了,仍然只在网格的卡片部分显示图像
-
查看我对 iOS 屏幕截图的编辑。这就是它目前正在做的事情。我需要图像覆盖整个页面作为背景
-
你的答案很好,试试吧
标签: xamarin xamarin.ios xamarin.forms