Android 上的 ListView 快速滚动

此特定于 Android 平台的功能用于在 ListView 中快速滚动浏览数据。 通过将 ListView.IsFastScrollEnabled 附加属性设置为 boolean 值在 XAML 中使用它:

<ContentPage ...
             xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core">
    <StackLayout Margin="20">
        ...
        <ListView ItemsSource="{Binding GroupedEmployees}"
                  GroupDisplayBinding="{Binding Key}"
                  IsGroupingEnabled="true"
                  android:ListView.IsFastScrollEnabled="true">
            ...
        </ListView>
    </StackLayout>
</ContentPage>

或者,可以使用 Fluent API 从 C# 使用它:

using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
...

var listView = new Xamarin.Forms.ListView { IsGroupingEnabled = true, ... };
listView.SetBinding(ItemsView<Cell>.ItemsSourceProperty, "GroupedEmployees");
listView.GroupDisplayBinding = new Binding("Key");
listView.On<Android>().SetIsFastScrollEnabled(true);

ListView.On<Android> 方法指定这一平台特定功能仅可在 Android 上运行。 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 命名空间中的 ListView.SetIsFastScrollEnabled 方法用于在 ListView 中快速滚动浏览数据。 此外,SetIsFastScrollEnabled 方法还可用于切换快速滚动,即通过调用 IsFastScrollEnabled 方法,返回是否启用快速滚动的结果:

listView.On<Android>().SetIsFastScrollEnabled(!listView.On<Android>().IsFastScrollEnabled());

结果是可以实现在 ListView 中快速滚动浏览数据,这会更改滚动块的大小:

特定于平台的 ListView FastScroll