android - Intercepted ScrollView interfering with child onClick events -
i've layout in custom scrollview has horizontal viewpager , textview below it. onclick of textview stops working if use interpretedscrollview instead of scrollview. need interpretedscrollview allow horizontal scroll in viewpager.
<com.package.interceptedscrollview <viewpager // scrolls horizontally interceptedscrollview /> ... <textview // try scrolling vertically touching imageview , doesn't scroll onclick="something"/> </com.package.interceptedscrollview> and custom scrollview
public class interceptedscrollview extends scrollview { gesturedetector mgesturedetector; private class verticalscrolldetector extends simpleongesturelistener { @override public boolean onscroll(motionevent e1, motionevent e2, float x, float y) { if (math.abs(y) > math.abs(x)) { // scrolling in y direction essentially. should scroll // vertically. return true; } // not of scroll in y. don't scroll. return false; } } public interceptedscrollview(context ctx, attributeset as) { super(ctx, as); mgesturedetector = new gesturedetector(ctx, new verticalscrolldetector()); setfadingedgelength(0); } @override public boolean onintercepttouchevent(motionevent event) { return super.onintercepttouchevent(event) && mgesturedetector.ontouchevent(event); } } why interceptedscrollview eating onclick of textview? how fix it?
my custom scrollview use totalsize of xscroll , yscroll. record current xpoint , ypoint,when click down. calculate when moving .
public class pagescrollview extends scrollview { private float xdistance, ydistance, lastx, lasty; public pagescrollview(context context, attributeset attrs) { super(context, attrs); } @override public boolean onintercepttouchevent(motionevent ev) { switch (ev.getaction()) { case motionevent.action_down: xdistance = ydistance = 0f; lastx = ev.getx(); lasty = ev.gety(); break; case motionevent.action_move: final float curx = ev.getx(); final float cury = ev.gety(); xdistance += math.abs(curx - lastx); ydistance += math.abs(cury - lasty); lastx = curx; lasty = cury; if(xdistance > ydistance) return false; } return super.onintercepttouchevent(ev); } }
Comments
Post a Comment