在xamarin表单中的Listview不使用表单的完整空间

时间:2017-09-28 07:01:36

标签: xamarin xamarin.ios xamarin.forms

我正在开发Xamarin表单跨平台应用程序。我有一个表单,我需要在listview中显示数据。

数据正在显示,但它没有使用整个空间,导致在底部保留不需要的空间。

enter image description here

我的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="BMTHomesApp.Views.ImportantAppointments">
    <ContentPage.Content>
        <StackLayout VerticalOptions="StartAndExpand">
            <ListView HasUnevenRows="True" RowHeight="100" HeightRequest="-1" x:Name="ListViewAppointments" VerticalOptions="StartAndExpand">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid Padding="20,0,0,0" ColumnSpacing="20">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="40"></RowDefinition>
                                    <RowDefinition Height="40"></RowDefinition>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="40"></ColumnDefinition>
                                    <ColumnDefinition Width="*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>

                                <!--<BoxView Color="#f7f7f7" Grid.Column="0" Grid.RowSpan="2"/>
                                <BoxView Color="#ffffff" Grid.Column="1" Grid.RowSpan="2"/>-->
                                <Image Grid.RowSpan="2" Grid.Column="0" x:Name="ImageAppointmentIcon" Source="AppointmentsIcon.png" Aspect="AspectFit"></Image>
                                <Label TextColor="#00344e" FontAttributes="Bold" Text="{Binding Subject}" Grid.Row="0" Grid.Column="1" VerticalTextAlignment="End"></Label>
                                <Label TextColor="#0073ae" Text="{Binding StartDate}" Grid.Row="1" Grid.Column="1" VerticalTextAlignment="Start"></Label>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <ActivityIndicator x:Name="ActLoder"  HorizontalOptions="CenterAndExpand" Color="#ffffff" VerticalOptions="CenterAndExpand"  />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

2 个答案:

答案 0 :(得分:1)

可以是ListView之后的ActivityIndi​​cator。它们被封装在StackLayout中,因此它们都会垂直占用空间。

如果您希望ActivityIndi​​cator显示在ListView的顶部,请将StackLayout替换为Grid。

不确定HeightRequest = -1是什么。

答案 1 :(得分:0)

我猜想StackLayout会导致您的布局问题。您正在堆叠Listview

ActivityIndicator ontop

如果您希望ActivityIndicator出现在与Listview相同的空间但居中,那么您可以尝试以下操作:

<ContentPage.Content>
    <Grid>
        <ListView HasUnevenRows="True" RowHeight="100" x:Name="ListViewAppointments" VerticalOptions="StartAndExpand">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="20,0,0,0" ColumnSpacing="20">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40"></RowDefinition>
                                <RowDefinition Height="40"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="40"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <!--<BoxView Color="#f7f7f7" Grid.Column="0" Grid.RowSpan="2"/>
                            <BoxView Color="#ffffff" Grid.Column="1" Grid.RowSpan="2"/>-->
                            <Image Grid.RowSpan="2" Grid.Column="0" x:Name="ImageAppointmentIcon" Source="AppointmentsIcon.png" Aspect="AspectFit"></Image>
                            <Label TextColor="#00344e" FontAttributes="Bold" Text="{Binding Subject}" Grid.Row="0" Grid.Column="1" VerticalTextAlignment="End"></Label>
                            <Label TextColor="#0073ae" Text="{Binding StartDate}" Grid.Row="1" Grid.Column="1" VerticalTextAlignment="Start"></Label>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        <ActivityIndicator x:Name="ActLoder"  HorizontalOptions="CenterAndExpand" Color="#ffffff" VerticalOptions="CenterAndExpand"  />
    </Grid>
</ContentPage.Content>