Forum Xamarin.Android

ViewPager scroll speed

Hello,
I'm trying to change the scrolling speed of a ViewPager, and i found this answer on stackoverflow:
http://stackoverflow.com/questions/8155257/slowing-speed-of-viewpager-controller-in-android/9731345#9731345

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

bye
Mirco

Posts

  • 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 {
            get{
                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.

    Bye

  • 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:
    http://stackoverflow.com/a/9731345

    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.

    Bye
    Mirco

  • Slow.2842Slow.2842 USMember ✭✭

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

Sign In or Register to comment.