android - Scrollview not flinging after onTouchListener attached -


i have scrollview has viewtreeobserver.onscrollchangedlistener not problem, once set ontouchlistener figure out when scrollview has stopped scrolling, flinging action on scrollview not happen anymore. here code:

if doesnt run method have ontouch event , flinging still happens:

@override     public boolean ontouch(view view, motionevent event) {         if (event.getaction() == motionevent.action_up) {             horizontalscrollclipping((scrollview)view, view.getscrolly());             return false;  //returning false instead of true         }         return false;     } 

if this, method inside ontouch event fires off, flinging scrollview not happen :

@override     public boolean ontouch(view view, motionevent event) {         if (event.getaction() == motionevent.action_up) {             horizontalscrollclipping((scrollview)view, view.getscrolly());             return true;  //returning true instead false         }         return false;     } 

and if this, scrolling on scrollview gets disabled:

@override     public boolean ontouch(view view, motionevent event) {         if (event.getaction() == motionevent.action_up) {             horizontalscrollclipping((scrollview)view, view.getscrolly());             return true;   //return true both         }         return true;     } 

here horizontalscrollclipping method shown in touch event:

private void horizontalscrollclipping(scrollview scrollview, int scrolly) {         if (scrolly > (image.getheight() * 0.60)) {             scrollview.smoothscrollto(0, image.getheight());         }     } 

just wondering if clue me in on why default flinging action scrollview gets disabled when ontouchlistener attached , returning true, , why method have inside ontouch event not fire off when im returning false. in advance, appreciated.

edit: instead of checking if user done scrolling during ontouch interface calculated if user done scrolling in onscrollchangedlistener so:

scrollview.getviewtreeobserver().addonscrollchangedlistener(new viewtreeobserver.onscrollchangedlistener() {             @override             public void onscrollchanged() {                 int scrolly = scrollview.getscrolly();                 if ((scrolly - lastscrolly) < 5 && (scrolly - lastscrolly) > 0) {                     horizontalscrollclipping((scrollview)scrollview, scrolly);                 }                 lastscrolly = scrolly;             }         }); 

where lastscrolly variable initialized @ top of class set 0.

if return true ontouch you're stating have handled event , no other listeners should attempt handle it. if had guess scrollview listener ontouch method , when return true scrollview's ontouch never called because method handled event.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -