【问题标题】:ListView padding before and after items项目前后的 ListView 填充
【发布时间】:2015-11-10 21:52:18
【问题描述】:

我的ListViews 在他们的孩子之前和之后都添加了大量的填充。

例如,我的主人中有以下ListView

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:viewModel="clr-namespace:ViewModel;assembly=App"
             x:Class="Pages.Master"
             Title="Menu">
  <ContentPage.BindingContext>
    <viewModel:MasterViewModel />
  </ContentPage.BindingContext>

  <ListView ItemsSource="{Binding Pages}"
            ItemSelected="ListView_OnItemSelected"
            BackgroundColor="Red">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <Label Text="S" BackgroundColor="White" />
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</ContentPage>

它呈现以下内容:

只要滚动一点,它就会显示第一个元素(即顶部的红色空间等于高度)

同样你可以一直滚动直到最后一项完全消失(即底部红色空间等于高度)

我不会在代码中更改任何视图的属性/样式 - 都是在 XAML 中完成的,那么为什么前后会有这么大的空间?

【问题讨论】:

    标签: xamarin xamarin.android xamarin.forms


    【解决方案1】:

    ListView.Header和ListView.Footer的渲染好像有问题

    我将以下内容添加到我的列表视图 XAML 中并删除了巨大的填充:

    <ListView.Header>
      <StackLayout HeightRequest="0" />
    </ListView.Header>
    <!-- ItemTemplate -->
    <ListView.Footer>
      <StackLayout HeightRequest="0" />
    </ListView.Footer>
    

    由于这个问题影响了我的所有列表视图,我选择将其作为全局应用样式添加到我的 App.xaml 中:

    <Style TargetType="ListView">
      <Setter Property="Header">
        <Setter.Value>
          <StackLayout HeightRequest="0" />
        </Setter.Value>
      </Setter>
      <Setter Property="Footer">
        <Setter.Value>
          <StackLayout HeightRequest="0" />
        </Setter.Value>
      </Setter>
    </Style>
    

    【讨论】:

      猜你喜欢
      • 2013-12-17
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多