android - Problem implementing vertical swipe in Gallery -
i asked similar question in android developers group haven't received response yet, figured i'd try luck here.
i want implement vertical swipe on gallery , have working... sort of. subclassed gallery override onfling , ondown methods.
here code used override these methods:
@override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { if (m_curtouchpos == no_current_touch_pos || m_callback == null) return super.onfling(e1, e2, velocityx, velocityy); float e1x = e1.getx(); float e1y = e1.gety(); float e2x = e2.getx(); float e2y = e2.gety(); float offpath = math.abs(e1x - e2x); float distance = math.abs(e1y - e2y); if (offpath < s_swipemaxoffpath && //math.abs(velocityy) >= s_swipeminvelocity && distance >= s_swipemindistance) { if (e1y > e2y) { m_callback.onswipeup(m_curtouchpos); //return true; } else if (e2y > e1y) { //todo: implement //m_callback.onswipedown(m_curtouchpos); //return true; } } m_curtouchpos = no_current_touch_pos; return super.onfling(e1, e2, velocityx, velocityy); } @override public boolean ondown(motionevent eve) { m_curtouchpos = pointtoposition((int)eve.getx(), (int)eve.gety()); return super.ondown(eve); }
the problem onfling doesn't called when vertical swipe... in order onfling method have press on item in gallery, slide little left or right, , swipe vertically.
horizontal swipes onfling method.
any ideas on how work?
ok, have found answer... ondown() method needs return true. call return super.ondown(eve) causing fail because default implementation returns false.
i found answer in post here on stackoverflow:
Comments
Post a Comment