Xamarin表示列表视图未填充Horizantal方向

时间:2016-07-04 00:38:44

标签: listview xamarin.ios xamarin.android xamarin.forms fill

当我使一些控件不可见时,我的Listview正在填充屏幕的一半。 列表视图位于网格控件中。以下是我的代码

    <?xml version="1.0" encoding="utf-8" ?>
<views:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:converters="clr-namespace:Sthotraani.Converters;assembly=Sthotraani"
             xmlns:behaviors="clr-namespace:Sthotraani.Behaviors;assembly=Sthotraani"
             xmlns:controls="clr-namespace:Sthotraani.CustomControls;assembly=Sthotraani"
             xmlns:views="clr-namespace:Sthotraani.Views;assembly=Sthotraani"
             x:Class="Sthotraani.Views.GodsPage"  Title="Sthotraani" x:Name="pgGod" >
  <ContentPage.Resources>
    <ResourceDictionary>
      <converters:ItemTappedEventArgsConverter x:Key="ItemTappedConverter" />
      <converters:BoolToImageConverter x:Key="booltoimage" />
      <converters:FileToImageConverter x:Key="FtoIConverter" />
      <converters:BoolToHeightConverter x:Key="BoolToHeight" />
      <converters:InvertBooleanConverter  x:Key="boolConvert"/>
    </ResourceDictionary>
  </ContentPage.Resources>
  <Grid HorizontalOptions="FillAndExpand">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid x:Name="gMain" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"  />
        <RowDefinition Height="{Binding ShowAd, Converter={StaticResource BoolToHeight},ConverterParameter=5|absolute}" />
        <RowDefinition Height="{Binding ShowAd,Converter={StaticResource BoolToHeight},ConverterParameter=5|auto}"  />
        <RowDefinition Height="5" />
        <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
      </Grid.ColumnDefinitions>
      <StackLayout x:Name="slMain" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" MinimumWidthRequest="1000" >
        <StackLayout BackgroundColor="#009688"  Padding="5" IsVisible="{Binding IsSearchVisisble}" Orientation="Horizontal" >
          <Entry x:Name="txtSearch" Text="{Binding SearchTerm}"  Placeholder="Enter sthotram name" PlaceholderColor="Gray"  FontSize="Micro"  TextColor="Black" BackgroundColor="White" HorizontalOptions="FillAndExpand" />
        </StackLayout>
        <BoxView HeightRequest="5" BackgroundColor="White" IsVisible="{Binding IsSearchVisisble, Converter={StaticResource boolConvert}}" />
        <controls:CarouselView ItemsSource="{Binding Gods}"
                               x:Name="cvGods"
                               SelectedItem="{Binding SelectedGod}"
                               BackgroundColor="White"
                               IsVisible="{Binding IsSearchVisisble, Converter={StaticResource boolConvert}}" >
          <controls:CarouselView.ItemTemplate>
            <DataTemplate>
              <StackLayout Padding="5,0,5,0" >
                <StackLayout VerticalOptions="FillAndExpand">
                  <StackLayout.Triggers>
                    <DataTrigger TargetType="StackLayout" Binding="{Binding IsSelected}" Value="true">
                      <Setter Property="BackgroundColor" Value="#B2DFDB"/>
                    </DataTrigger>
                    <DataTrigger TargetType="StackLayout" Binding="{Binding IsSelected}" Value="false">
                      <Setter Property="BackgroundColor" Value="#FFFFFF"/>
                    </DataTrigger>
                  </StackLayout.Triggers>
                  <Image Source="{Binding ImageName,Converter={StaticResource FtoIConverter}}"   HorizontalOptions="Center" VerticalOptions="Center" />
                </StackLayout>
                <Label Text="{Binding Name}"
                       FontSize="Micro"
                       TextColor="Black"
                       HorizontalTextAlignment="Center" />
              </StackLayout>
            </DataTemplate>
          </controls:CarouselView.ItemTemplate>
        </controls:CarouselView>
      </StackLayout>
      <ContentView
                  Grid.Row="0"
                  Grid.Column="0"
                  VerticalOptions="Fill"
                  HorizontalOptions="Fill"
                  IsVisible="{Binding IsBusy}"
                  BackgroundColor="#22009485"
                  Padding="10, 0">
        <ActivityIndicator VerticalOptions="Center"
                           HorizontalOptions="CenterAndExpand"
                           IsVisible="{Binding IsBusy}"
                           IsRunning="{Binding IsBusy}"
                           Color="#F98F1C"   />
      </ContentView>
      <BoxView BackgroundColor="Red" x:Name="bvTop"
               HorizontalOptions="FillAndExpand"
               HeightRequest="5"
               Grid.Row="1" Grid.Column="0"></BoxView>
      <views:AdMobView WidthRequest="320"
                       HeightRequest="50"
                       x:Name="amvAds"
                       HorizontalOptions="CenterAndExpand"
                       Grid.Row="2"
                       Grid.Column="0"/>
      <BoxView BackgroundColor="#009688"
               x:Name="bvBottom"
               HorizontalOptions="FillAndExpand"
               HeightRequest="5"
               Grid.Row="3"
               Grid.Column="0"></BoxView>

      <ListView x:Name="lvSthotras"
                VerticalOptions="Start"
                SeparatorVisibility="None"
                ItemsSource="{Binding Sthotraas}"
                HasUnevenRows="True"
                HorizontalOptions="FillAndExpand"
                CachingStrategy="RecycleElement"
                SelectedItem="{Binding SelectedSthotram}"
                Grid.Row="4"
                Grid.Column="0">
        <ListView.Behaviors>
          <behaviors:ListViewSelectedItemBehavior Command="{Binding CmdListItemTapped}" Converter="{StaticResource ItemTappedConverter}" />
        </ListView.Behaviors>
        <ListView.ItemTemplate>
          <DataTemplate>
            <ViewCell>
              <ViewCell.View>
                <StackLayout>
                  <StackLayout Padding="10" Orientation="Horizontal">
                    <Image HorizontalOptions="Start" Source="{Binding IsFavorite,Converter={StaticResource booltoimage},ConverterParameter=pickedstar.png|star.png}" VerticalOptions="CenterAndExpand" >
                      <Image.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding Path=BindingContext.CmdFavoriteTapped, Source={x:Reference pgGod}}" CommandParameter="{Binding SthotraID}" />
                      </Image.GestureRecognizers>
                    </Image>
                    <Label  Text="{Binding Name}" HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand"   FontSize="Small" />
                  </StackLayout>
                  <BoxView BackgroundColor="#009688"
                           HeightRequest="1"
                           HorizontalOptions="FillAndExpand" />
                </StackLayout>
              </ViewCell.View>
            </ViewCell>
          </DataTemplate>
        </ListView.ItemTemplate>
      </ListView>
      <ContentView Grid.Row="4"
                   Grid.Column="0"
                   VerticalOptions="Fill"
                   HorizontalOptions="Fill"
                   IsVisible="{Binding IsBusy}"
                   BackgroundColor="#22009485"
                   Padding="10, 0">
        <ActivityIndicator VerticalOptions="Center"
                           HorizontalOptions="CenterAndExpand"
                           IsVisible="{Binding IsBusy}"
                           IsRunning="{Binding IsBusy}"
                           Color="#F98F1C"   />
      </ContentView>
    </Grid>
    <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"  Grid.Row="0" Grid.Column="0" IsVisible="{Binding IsOffline}" BackgroundColor="#009688">
    <StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="Fill" Spacing="20" Padding="25">
      <Label FontSize="Large" TextColor="White"  >It seems you are not connected to internet, please check your network settings and click retry</Label>
      <Button Text="Retry" Command="{Binding CmdRetryNetwork}" Style="{StaticResource btn}"/>
    </StackLayout>
    </StackLayout>
  </Grid>
  <ContentPage.ToolbarItems>
    <ToolbarItem Text="Search" Command="{Binding ToggleSearchCmd}" Icon="{Binding IsSearchVisisble,Converter={StaticResource booltoimage},ConverterParameter=closeicon.png|SearchIcon.png}"  Order="Primary" Priority="1"  >
    </ToolbarItem>
  </ContentPage.ToolbarItems>
</views:BasePage>

以下是我展示的部分隐藏一些控件

<StackLayout x:Name="slMain" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" MinimumWidthRequest="1000" >
        <StackLayout BackgroundColor="#009688"  Padding="5" IsVisible="{Binding IsSearchVisisble}" Orientation="Horizontal" >
          <Entry x:Name="txtSearch" Text="{Binding SearchTerm}"  Placeholder="Enter sthotram name" PlaceholderColor="Gray"  FontSize="Micro"  TextColor="Black" BackgroundColor="White" HorizontalOptions="FillAndExpand" />
        </StackLayout>
        <BoxView HeightRequest="5" BackgroundColor="White" IsVisible="{Binding IsSearchVisisble, Converter={StaticResource boolConvert}}" />
        <controls:CarouselView ItemsSource="{Binding Gods}"
                               x:Name="cvGods"
                               SelectedItem="{Binding SelectedGod}"
                               BackgroundColor="White"
                               IsVisible="{Binding IsSearchVisisble, Converter={StaticResource boolConvert}}" >
          <controls:CarouselView.ItemTemplate>
            <DataTemplate>
              <StackLayout Padding="5,0,5,0" >
                <StackLayout VerticalOptions="FillAndExpand">
                  <StackLayout.Triggers>
                    <DataTrigger TargetType="StackLayout" Binding="{Binding IsSelected}" Value="true">
                      <Setter Property="BackgroundColor" Value="#B2DFDB"/>
                    </DataTrigger>
                    <DataTrigger TargetType="StackLayout" Binding="{Binding IsSelected}" Value="false">
                      <Setter Property="BackgroundColor" Value="#FFFFFF"/>
                    </DataTrigger>
                  </StackLayout.Triggers>
                  <Image Source="{Binding ImageName,Converter={StaticResource FtoIConverter}}"   HorizontalOptions="Center" VerticalOptions="Center" />
                </StackLayout>
                <Label Text="{Binding Name}"
                       FontSize="Micro"
                       TextColor="Black"
                       HorizontalTextAlignment="Center" />
              </StackLayout>
            </DataTemplate>
          </controls:CarouselView.ItemTemplate>
        </controls:CarouselView>
      </StackLayout>

每当我将carouselview隐藏在listview上方时,只会填充屏幕的一半。所有控件都有HorizantalOptions =&#34; FillAndExpand&#34;不知道我做错了什么。以下链接视频将向您显示行为

这是设备方向垂直时,一切正常

https://youtu.be/aamFaiNpUE4

这是设备是水平的,这是当listview行为怪异的时候。

https://youtu.be/DX2nFJnLn3o

请帮助我。谢谢

0 个答案:

没有答案