2017-09-28 55 views
0

我的工作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> 

回答

1

可能是ListView控件後ActivityIndi​​cator。它們被封裝在一個StackLayout中,所以都會垂直佔用空間。

如果你想在ActivityIndi​​cator出現在ListView控件的頂部,與網格替換StackLayout。

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

+0

我設置HeightRequest = -1看無論是通過使用它將使用表格高度,但沒有工作...即使我刪除活動指標..然後也是相同的結果 – Mahajan344

+0

擺脫活動指標和堆棧佈局,看看是否列表視圖佔用整個頁面。你也應該設置HasUnevenRows = true或RowHeight = 100,你不需要兩者。 –

+0

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

0

我猜想,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>