Android 上的 TabbedPage 页面轻扫

此 Android 平台特定功能可用于在 TabbedPage 中通过横向手指手势实现轻扫翻页。 通过将 TabbedPage.IsSwipePagingEnabled 附加属性设置为 boolean 值在 XAML 中使用它:

<TabbedPage ...
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
            android:TabbedPage.OffscreenPageLimit="2"
            android:TabbedPage.IsSwipePagingEnabled="true">
    ...
</TabbedPage>

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

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

On<Android>().SetOffscreenPageLimit(2)
             .SetIsSwipePagingEnabled(true);

TabbedPage.On<Android> 方法指定此平台特定仅在 Android 上运行。 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 命名空间中的 TabbedPage.SetIsSwipePagingEnabled 方法用于启用在 TabbedPage 中的页面之间进行轻扫的操作。 此外,Xamarin.Forms.PlatformConfiguration.AndroidSpecific 命名空间中的 TabbedPage 类还具有可启用此平台特定功能的 EnableSwipePaging 方法,以及禁用此平台特定功能的 DisableSwipePaging 方法。 TabbedPage.OffscreenPageLimit 附加属性和 SetOffscreenPageLimit 方法用于设置当前页面任意一侧应保持闲置状态的页数。

结果是启用了对 TabbedPage 显示的页面进行轻扫分页的操作:

通过 TabbedPage 轻扫分页