Android Monitor ScrollView Swipe

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.