【发布时间】:2018-02-22 10:14:11
【问题描述】:
当我尝试使用自定义布局制作列表视图时,它在 UWP 上看起来与在 Android 上完全不同。如何在不为每个平台制作页面的情况下使它们在所有平台上看起来都一样? 我尝试让我的应用看起来像线框。
我尝试将对象可视化为具有背景图像和两个标签的视单元。
我目前正在使用 Xamarin 和 .NET 标准作为代码共享策略开发适用于 Android 和 UWP 的应用程序。
这个项目的想法是在共享项目(上层项目文件)中制作每个视图/业务逻辑,因为应用程序不会使用任何平台特定的功能。
这是我的 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="inleiding.Views.SubList"
Title="Your pokélist"
NavigationPage.BackButtonTitle="go back"
NavigationPage.HasBackButton="True"
NavigationPage.HasNavigationBar="True"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Label Text="Cars" FontSize="Large" TextColor="LightGray" />
<ListView x:Name="lvwPok" ItemSelected="lvwPok_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<RelativeLayout>
<Image VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
Source = "{Binding Pic}"></Image>
<Grid
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
BackgroundColor="Transparent"
>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" WidthRequest="100" HeightRequest="100" Source = "{Binding ImgPok}">
</Image>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Spec}" />
<Label Grid.Row="0" Grid.Column="1" Text="{ Binding Type }" />
</Grid>
</RelativeLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
我没有想法。
【问题讨论】:
标签: c# xamarin.forms .net-standard-2.0