Решение:
Я попробовал вам первую идею Add a blank, disabled Cell which only shows on Android.
, это немного сложно, давайте сделаем это шаг за шагом:
Во-первых, я добавляю белую метку в конце каждого TableSection
в качестве пробела, вот мой Xaml
, не забудьте установить tableview.HasUnevenRows="True"
:
<ContentPage.Content >
<TableView Intent="Settings" HasUnevenRows="True">
<TableView.BindingContext>
<local:Model/>
</TableView.BindingContext>
<TableRoot>
<TableSection Title="Getting Started">
<SwitchCell Text="New Voice Mail" />
<SwitchCell Text="New Mail" On="true" />
<!--use as space-->
<ViewCell x:Name="cell2">
<StackLayout x:Name="s1">
<Label Text="space"
TextColor="#f35e20" BackgroundColor="White" HorizontalTextAlignment="Center" x:Name="spacelabel2"/>
</StackLayout>
</ViewCell>
</TableSection>
<TableSection Title="Getting Started22222" >
<ViewCell>
<StackLayout Orientation="Vertical">
<Label Text="left"
TextColor="#f35e20" BackgroundColor="Blue"/>
<Label Text="right"
HorizontalOptions="EndAndExpand"
TextColor="#503026" BackgroundColor="Orange"/>
</StackLayout>
</ViewCell>
<!--use as space-->
<ViewCell x:Name="cell1">
<StackLayout x:Name="s2">
<Label Text="space"
TextColor="#f35e20" BackgroundColor="White" HorizontalTextAlignment="Center" x:Name="spacelabel1"/>
</StackLayout>
</ViewCell>
</TableSection>
<TableSection Title="Getting Started33333" >
<ViewCell>
<StackLayout Orientation="Vertical">
<Label Text="left"
TextColor="#f35e20" BackgroundColor="Blue"/>
<Label Text="right"
HorizontalOptions="EndAndExpand"
TextColor="#503026" BackgroundColor="Orange"/>
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
Я дал ViewCell
имя, подобное cell1
и cell2
, затем в приведенном ниже коде я использую Device.RuntimePlatform
для различения iOS
или Android
:
protected override void LayoutChildren(double x, double y, double width, double height)
{
base.LayoutChildren(x, y, width, height);
if (Device.RuntimePlatform == Device.Android)
{
spacelabel1.IsVisible = true;
spacelabel2.IsVisible = true;
}
else
{
cell2.Height = 0.01;
cell1.Height = 0.01;
cell1.View.IsVisible = false;
cell2.View.IsVisible = false;
}
}
Так, в iOS эти белые метки не будут отображаться на этой странице, в Android эти метки будут появляться в конце каждого раздела. Вы можете установить цвет фона метки так же, как цвет TableSections
, тогда между ними будет выглядеть пробел. Ответьте мне, если у вас возникли проблемы.