I'm currently developing for Android using C# and Xamarin.
I want to add a listener to the scroll views that I have within my app, so that it picks up when a user is touching the scroll bar.
How can I go about this?
Thanks!
Refer to this , in xamarin.android usage like this
public class MainActivity : Activity, IOnScrollChangedListener
{
ScrollView msv;
public void OnScrollChanged()
{
float scrollY = msv.ScrollX;
float scrollX = msv.ScrollY;
System.Diagnostics.Debug.Write("x:=" + scrollY + " y=" + scrollX );
//do something
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
msv = FindViewById<ScrollView>(Resource.Id.sv);
msv.ViewTreeObserver.AddOnScrollChangedListener(this);
}
}
you can also write up a class MyScrollView
to extend ScrollView
,and then override OnTouchEvent
or onScrollChanged(int x, int y, int oldX, int oldY)
method to implement your function.