We need to monitor the slide of the scroview, such as how many distances have been slid, and whether to slide to the top or bottom of the layout. Unfortunately, the SDK does not have a corresponding method, but it does provide a
protected void onscrollchanged (intintint. intint
Obviously this method cannot be called by the outside world, so it needs to be exposed, the solution is to write an interface
/***/Publicinterface scrollviewlistener {void Onscrollchanged (Observablescrollview observablescrollview,int x,int y,intint oldy);}
Then rewrite the ScrollView class to provide it with the callback interface written above
PackageCom.liu.titlealpha.view;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.widget.ScrollView;/*** Created by Liu Nan on 2016/8/21 0021.17:23*/ Public classObservablescrollviewextendsScrollView {PrivateScrollviewlistener mscrollviewlistener=NULL; Public voidSetscrollviewlistener (Scrollviewlistener scrollviewlistener) {Mscrollviewlistener=Scrollviewlistener; } PublicObservablescrollview (Context context) {Super(context); } PublicObservablescrollview (Context context, AttributeSet attrs) {Super(context, attrs); } PublicObservablescrollview (context context, AttributeSet attrs,intdefstyleattr) { Super(context, attrs, defstyleattr); } @Overrideprotected voidOnscrollchanged (intXintYintOLDX,intOldy) { Super. onscrollchanged (x, Y, OLDX, oldy); if(Mscrollviewlistener! =NULL) {mscrollviewlistener.onscrollchanged ( This, x, Y, OLDX, oldy); } }}
Layout, with this scrollview of rewriting
Android Monitor ScrollView Swipe