TabbedPage Page Swiping on Android
This Android platform-specific is used to enable swiping with a horizontal finger gesture between pages in a TabbedPage
. It's consumed in XAML by setting the TabbedPage.IsSwipePagingEnabled
attached property to a boolean
value:
<TabbedPage ...
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.OffscreenPageLimit="2"
android:TabbedPage.IsSwipePagingEnabled="true">
...
</TabbedPage>
Alternatively, it can be consumed from C# using the fluent API:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
...
On<Android>().SetOffscreenPageLimit(2)
.SetIsSwipePagingEnabled(true);
The TabbedPage.On<Android>
method specifies that this platform-specific will only run on Android. The TabbedPage.SetIsSwipePagingEnabled
method, in the Xamarin.Forms.PlatformConfiguration.AndroidSpecific
namespace, is used to enable swiping between pages in a TabbedPage
. In addition, the TabbedPage
class in the Xamarin.Forms.PlatformConfiguration.AndroidSpecific
namespace also has a EnableSwipePaging
method that enables this platform-specific, and a DisableSwipePaging
method that disables this platform-specific. The TabbedPage.OffscreenPageLimit
attached property, and SetOffscreenPageLimit
method, are used to set the number of pages that should be retained in an idle state on either side of the current page.
The result is that swipe paging through the pages displayed by a TabbedPage
is enabled: