Frontier: Sometimes, ListView item to display more fields, considering the display problem, the item has to be nested outside scrollview to achieve, so the problem comes, when ListView need to do click events, The Listvew Click event was intercepted because of ScrollView's nesting use: The ListView had to be rewritten to achieve it.
/** * * @author Author: Isea Star * * @da2016 year October 24: * * @toTODO Class Description: Resolve ListView nested Scrollview,scrollview Intercept ListView Item Click event Solution * * * nested ScrollView in ListView, found smooth vertical slide is normal, but cannot click ListView Item.
After querying the Android distribution mechanism to resolve, inherit ListView rewrite ListView's Onintercepttouchevent. * * Onintercepttouchevent Always call ListView ontouchevent Guarantee ListView events are performed, * super.onintercepttouchevent (EV)
does not intercept the horizontal slip that needs to be passed to the ScrollView. * * public class Mylistview extends ListView {private int flag = 0; private float startx; private float starty; public myl Istview (context) {Super [context];//TODO auto-generated constructor stub} public Mylistview Tributeset attrs, int defstyle) {Super (context, attrs, defstyle);//TODO auto-generated constructor stub} public MyList View (context, AttributeSet attrs) {Super (context, attrs);//TODO auto-generated constructor stub} @Override pub Lic boolean onintercepttouchevent (motionevent ev) {//Always invokes ListView touch event handling ontouchevent (EV); if (ev.getaction () = = Mot Ionevent.action_down) {startx = Ev.getx ();
Starty = Ev.gety ();
return false; } if (ev.getaction () = = Motionevent.action_move) {Float scollx = Ev.getx ()-startx; float scolly = Ev.gety ()-starty; /judge whether it is horizontal or vertical, or vertical, to block move events and up events (no interception will be performed simultaneously by ListView and ScrollView) if (Math.Abs (SCOLLX) < Math.Abs (scolly)) {flag = 1
;
return true;
return false; } if (ev.getaction () = = motionevent.action_up) {if (flag = = 1) {return true;} return false;} return SUPER.ONINTERCEPTT
Ouchevent (EV); }
}
The above is a small set to introduce the Android ListView of the item nested ScrollView solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!