列表视图中xamarin形式不使用形式

问题描述:

我的工作Xamarin的充分空间形成跨平台的应用程序。我有一个表单,我需要在listview中显示数据。列表视图中xamarin形式不使用形式

数据显示,但它不是使用导致在底部保持了不必要的空间整个空间。

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> 

可能是ListView控件后ActivityIndi​​cator。它们被封装在一个StackLayout中,所以都会垂直占用空间。

如果你想在ActivityIndi​​cator出现在ListView控件的顶部,与网格替换StackLayout。

不知道什么HeightRequest = -1是有。

+0

我设置HeightRequest = -1看无论是通过使用它将使用表格高度,但没有工作...即使我删除活动指标..然后也是相同的结果 – Mahajan344

+0

摆脱活动指标和堆栈布局,看看是否列表视图占用整个页面。你也应该设置HasUnevenRows = true或RowHeight = 100,你不需要两者。 –

+0

大概RowHeight = 100,看你如何硬编码你的行高。 –

我猜想,StackLayout导致您的布局问题。您堆叠Listview ontop的一个ActivityIndicator

的如果你想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>