在列表的所有元素之后,有一个空白区域。ListView.Height = 610它仍然是由于默认的事实。ListView 不会调整到其所有 Item 的高度,除非它们的组合高度大于 610。
如何解决这个问题?如何确保这个空间(额外高度)不存在?
从这里尝试了解决方案,但他们没有帮助......
PS 请不要提供为 ListView 设置固定高度的选项。这个选项对我不起作用。
更新
页面布局:
<ScrollView>
<StackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<custom:CustomFrame CornerRadius="0, 0, 0, 10" BackgroundColor="#f9f9f9" HorizontalOptions="Start">
<Label Text="{Binding CurrentTicket.Number, StringFormat='Билет {0}'}" />
</custom:CustomFrame>
<custom:CustomFrame Grid.Column="1" CornerRadius="0, 0, 10, 0" WidthRequest="60" BackgroundColor="#f9f9f9" HorizontalOptions="End">
<Label Text="{Binding TimeLeft}" HorizontalOptions="Center" />
</custom:CustomFrame>
</Grid>
<Label Text="{Binding CurrentTicket.Question}" FontSize="24" HorizontalTextAlignment="Center" TextColor="#0051DE" Margin="15, 20"/>
<ListView x:Name="List" HasUnevenRows="True" SeparatorVisibility="None" ItemsSource="{Binding CurrentTicket.Answers}" SelectedItem="{Binding SelectedAnswer}" VerticalOptions="Start">
<ListView.ItemTemplate>
<DataTemplate>
<custom:CustomViewCell SelectedItemBackgroundColor="White">
<ViewCell.View>
<custom:CustomFrame Padding="15, 10" Margin="10, 5" CornerRadius="10" BackgroundColor="#F8FBFF">
<Label Text="{Binding Value}" FontSize="17" TextColor="#464E56"/>
<custom:CustomFrame.Triggers>
<DataTrigger TargetType="custom:CustomFrame" Binding="{Binding IsSelected}" Value="True">
<Setter Property="BackgroundColor" Value="#9DF2FF"/>
</DataTrigger>
</custom:CustomFrame.Triggers>
</custom:CustomFrame>
</ViewCell.View>
</custom:CustomViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<custom:CustomFrame BackgroundColor="#f9f9f9" CornerRadius="0, 10, 0, 0">
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding TestProgress.TotalPassedTickets}" />
<Span Text="/" />
<Span Text="{Binding TestProgress.TotalTickets}" />
</FormattedString>
</Label.FormattedText>
</Label>
</custom:CustomFrame>
<Button Grid.Column="1" Text="Дальше" BackgroundColor="#FFFFFF" BorderColor="#f1f1f1" BorderWidth="1" CornerRadius="0" HorizontalOptions="End" Padding="50, 20" Command="{Binding Continue}"/>
</Grid>
</StackLayout>
</ScrollView>

我自己也遇到过这个问题,找到的解决方法如下:放弃ListView,改用BindableLayout。代码示例:
在此处阅读有关 BindableLayout的更多信息。