I'm using a TabbedPage.
Whenever I select a new Tab, there is a sliding animation. I would like to disable this.
There is a Xamarin Sample that does this, without the sliding animation. How can I replicate this?
I'm using a custom ToolBar and a TabBar, and also a FormsAppCompatActivity in my AppActivity.
The Sample provided by Xamarin isn't, so I'm not sure where I can disable these animations.
Thank you
Similar to the Native Android approach described here:
[assembly: ExportRenderer(typeof(TabsPage), typeof(TabsPageRenderer))] namespace App.Droid.Renderers { public class TabsPageRenderer : TabbedPageRenderer { ViewPager _viewPager; TabLayout _tabLayout; protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e) { base.OnElementChanged(e); for (int i = 0; i < ChildCount; i++) { var v = GetChildAt(i); if (v is ViewPager) _viewPager = (ViewPager)v; else if (v is TabLayout) _tabLayout = (TabLayout)v; } _viewPager.SetPageTransformer(true, new NoAnimationPageTransformer()); } } public class NoAnimationPageTransformer : Java.Lang.Object, Android.Support.V4.View.ViewPager.IPageTransformer { public void TransformPage(Android.Views.View view, float position) { if (position < 0) { view.ScrollX = (int)((float)(view.Width) * position); } else if (position > 0) { view.ScrollX = -(int)((float)(view.Width) * -position); } else { view.ScrollX = 0; } } } }
Answers
Similar to the Native Android approach described here:
With Xamarin.Forms 3.0 and above, the following code will work:
'[assembly: ExportRenderer(typeof(TabbedPage), typeof(TabsPageRenderer))]
namespace App.Droid.Renderers
{
public class TabsPageRenderer : TabbedPageRenderer
{
Context _context;
ViewPager _viewPager;
TabLayout _tabLayout;
}'
Hi,
I have tried the code you both suggested, but
GetChildAt
returns aRelativeLayout
(probably because I'm using a bottom tab layout). I don't suppose you guys know a way around it?Thanks!
Have you found a solution @JJohnSmith.0620?
Have you found a solution @JJohnSmith.0620?
If you are using bottom tab layout just set
android:TabbedPage.IsSmoothScrollEnabled="false"
inside the tag TabbedPage