谢谢@PaulBurke +1
Xamarin解决方案
using Android.Content; using Android.Runtime; using Android.Util; using Android.Widget; using System; public class CustomScrollView : ScrollView { public event EventHandler FlingEnded; public event EventHandler FlingStarted; private Action ScrollChecker; private int PreviousPosition; private const int DELAY_MILLIS = 100; public CustomScrollView(Context context) : base(context) => Init(); public CustomScrollView(Context context, IAttributeSet attrs) : base(context, attrs) => Init(); public CustomScrollView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) => Init(); public CustomScrollView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) => Init(); public CustomScrollView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) { } private void Init() { ScrollChecker = () => { int position = ScrollY; if (PreviousPosition - position == 0) { FlingEnded?.Invoke(this, new EventArgs()); RemoveCallbacks(ScrollChecker); } else { PreviousPosition = ScrollY; PostDelayed(ScrollChecker, DELAY_MILLIS); } }; } public override void Fling(int velocityY) { base.Fling(velocityY); FlingStarted?.Invoke(this, new EventArgs()); Post(ScrollChecker); } }
用法:
myCustomScrollView.FlingEnded += myCustomScrollView_FlingEnded; protected void myCustomScrollView_FlingEnded(object sender, EventArgs e) => { //Do onFlingEnded code here };