Forum Xamarin.Android

ViewPager scroll speed

I'm trying to change the scrolling speed of a ViewPager, and i found this answer on stackoverflow:

basically I should access to "mScroller" private Field and substitute it with my own scroller Class. Is it possible in MFA?



  • MircoCortecchiaMircoCortecchia USMember

    I've been able to manage this. I've extracted the Field in my inerithed ViewPager, in this way:

         Scroller _customScroller;
        public Scroller CustomScroller {
                return _customScroller;
            set {
                IntPtr ViewPagerClass   = JNIEnv.FindClass ("android/support/v4/view/ViewPager");
                IntPtr mScrollerProperty = JNIEnv.GetFieldID (ViewPagerClass, "mScroller", "Landroid/widget/Scroller;");
                if (value != null) {
                    JNIEnv.SetField (this.Handle, mScrollerProperty, value.Handle);
                _customScroller = value;

    I hope this could help, if someone have the same problem.


  • AditiAditi INMember

    Hi MircoCortecchia,

    I'm an Android developer and am new to Xamarin.

    Can you please tell me how to use the above CustomScroller class to control View Pager scroll speed.

    Thanks in advance !

  • Hi Aditi,

    Look at this answer on stackoverflow:

    it explain how to handle viewscroller speed in android.

    Simply inherit a FixedSpeedScroller (or whatever you like) class from Scroller.

    Then assign it to the CustomScroller property above.


  • Slow.2842Slow.2842 USMember ✭✭

    You can use var klass = Java.Lang.Class.FromType(typeof(YourClass));

Sign In or Register to comment.