Android 上的 ListView 快速滚动

此 .NET Multi-platform App UI (.NET MAUI) Android 平台特定功能用于实现在 ListView 中快速滚动浏览数据。 其使用方式为,在 XAML 中将 ListView.IsFastScrollEnabled 附加属性设置为 boolean 值:

<ContentPage ...
             xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls">
    <StackLayout>
        ...
        <ListView ItemsSource="{Binding GroupedEmployees}"
                  GroupDisplayBinding="{Binding Key}"
                  IsGroupingEnabled="true"
                  android:ListView.IsFastScrollEnabled="true">
            ...
        </ListView>
    </StackLayout>
</ContentPage>

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

using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
...

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

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

listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().SetIsFastScrollEnabled(!listView.On<Microsoft.Maui.Controls.PlatformConfiguration.Android>().IsFastScrollEnabled());

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

ListView FastScroll Platform-Specific.