Android 上的 TabbedPage 頁面撥動

Download Sample 下載範例

此 Android 平台專屬功能可用來在 中的 TabbedPage頁面之間使用水準手指手勢來撥動。 將附加屬性設定 TabbedPage.IsSwipePagingEnabledboolean 值,以在 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上執行。 命名空間 TabbedPage.SetIsSwipePagingEnabled 中的 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 方法可用來在 中的 TabbedPage頁面之間撥動。 此外, TabbedPage 命名空間中的 Xamarin.Forms.PlatformConfiguration.AndroidSpecific 類別也具有 EnableSwipePaging 可啟用此平臺特定的方法,以及 DisableSwipePaging 停用此平臺特定的方法。 TabbedPage.OffscreenPageLimit附加屬性和 SetOffscreenPageLimit 方法可用來設定應該在目前頁面任一端處於閑置狀態的頁數。

結果是啟用撥動分頁顯示的頁面 TabbedPage

Swipe paging through a TabbedPage