Xamarin.Forms: неправильный расчет высоты списка? - PullRequest
0 голосов
/ 27 февраля 2019

Почему в надписях внизу отображается только половина текста?

Это мой xaml.Область просмотра списка - 300, и каждая строка просмотра списка - 100 (задается в <On Platform="Android">100</On>).

Каждая ViewCell имеет 4 строки, каждая строка - 25, всего 100 (высота строки списка просмотра)).

Поэтому я не понимаю, почему отображается только половина текста внизу, или почему пространство, занимаемое строками 0 и 1 столбца 2, не является точно половиной общей высоты.

<Grid RowSpacing="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="100" />
        <RowDefinition Height="300" />
    </Grid.RowDefinitions>
    <StackLayout Grid.Row="0" x:Name="MapGrid">
        <maps:Map WidthRequest="960" HeightRequest="100" 
              x:Name="MyMap" IsShowingUser="true"/>
    </StackLayout>
    <StackLayout Grid.Row="1" x:Name="listSection" HeightRequest="300">
        <ListView x:Name="ListView_Pets">
            <ListView.RowHeight>
                <OnPlatform x:TypeArguments="x:Int32">
                    <On Platform="Android">100</On>
                </OnPlatform>
            </ListView.RowHeight>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                                <RowDefinition Height="25"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50*" />
                                <ColumnDefinition Width="25*"/>
                                <ColumnDefinition Width="25*"/>
                            </Grid.ColumnDefinitions>
                            <Label Text="Name" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="Black" Grid.Row="0" Grid.Column="0"/>
                            <Label Text="Address" HorizontalTextAlignment="Center" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" Grid.Row="1" Grid.Column="0"/>
                            <Label Text="Price1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="White" BackgroundColor="#2FA4D9" Grid.Row="0" Grid.Column="2"/>
                            <Label Text="Price2" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" FontSize="15" TextColor="White" BackgroundColor="#2FA4D9" Grid.Row="1" Grid.Column="2"/>
                            <Label Text="Tag1" Grid.Row="0" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Grid.Column="1" FontSize="Micro"/>
                            <Label Text="Tag2" Grid.Row="1" VerticalTextAlignment="Center" HorizontalTextAlignment="End" Grid.Column="1" FontSize="Micro"/>
                            <StackLayout Grid.Row="3" Grid.Column="0">
                                <StackLayout Orientation="Horizontal" >
                                    <Label Text="Text1" FontSize="10" VerticalTextAlignment="Start" TextColor="Black" />
                                    <Label Text="Text2" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" />
                                    <Label Text="Text3" VerticalTextAlignment="Start" FontSize="10" TextColor="Black" />
                                </StackLayout>
                            </StackLayout>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</Grid>

Вот скриншот:

enter image description here

1 Ответ

0 голосов
/ 27 февраля 2019

Это потому, что Grid внутри ViewCell имеет значения по умолчанию RowSpacing и ColumnSpacing.Чтобы переопределить это, просто установите <Grid RowSpacing=0 ColumnSpacing=0>

...