The Dispatchtouchevent method is used for the distribution of events, and all events in Android must be distributed through this method, and then decide whether to consume the current event itself or continue to distribute it to child control processing. Returns true to indicate that the distribution is not continued and the event is not consumed. Returns false to continue the distribution, if ViewGroup is distributed to onintercepttouchevent to determine whether to intercept the event.
The Ontouchevent method is used to handle the event, which returns true to indicate that the consumer handles the current event, returns false and does not process, and gives the child control to continue distribution.
Onintercepttouchevent is a viewgroup in the method, the view is not, it is responsible for the interception of events, return true to intercept the current event, do not continue to distribute, to their own ontouchevent to handle. return false to Not intercept, continue to pass. This is a unique method for ViewGroup, because there may be sub-view in ViewGroup, and in Android view it is no longer possible to include child view (iOS can).
Package Com.lwj.app.customview;import Android.content.context;import android.graphics.pointf;import Android.support.v4.view.viewpager;import Android.util.attributeset;import android.view.MotionEvent; Public classChildviewpager extends viewpager{/** Touch the point when pressed **/PointF DOWNP=NewPointF (); /** The current point when touching **/PointF curp=NewPointF (); Onsingletouchlistener Onsingletouchlistener; PublicChildviewpager (Context context, AttributeSet Attrs) {Super (context, attrs); //TODO auto-generated Constructor stub } PublicChildviewpager (Context context) {super (context); //TODO auto-generated Constructor stub} @Override Publicboolean ontouchevent (Motionevent arg0) {//TODO auto-generated Method Stub//each time the Ontouch event is logged, the current pressed coordinates are recorded if(Getchildcount () <=1) { returnsuper.ontouchevent (arg0); } curp.x=Arg0.getx (); CURP.Y=arg0.gety (); if(arg0.getaction () = =Motionevent.action_down) { //record the coordinates at the time of the press//remember not to use DOWNP = Curp, so that when changing the Curp, DOWNP will also changedownp.x =Arg0.getx (); DOWNP.Y=arg0.gety (); //This code is to inform his father that Viewpager is now doing the operation of this control, do not interfere with my operationGetParent (). Requestdisallowintercepttouchevent (true); } if(arg0.getaction () = =motionevent.action_move) { //This code is to inform his father that Viewpager is now doing the operation of this control, do not interfere with my operationGetParent (). Requestdisallowintercepttouchevent (true); } if(arg0.getaction () = = Motionevent.action_up | | arg0.getaction () = =motionevent.action_cancel) { //determine if the coordinates of the press and drop are at a point when up//if it is a point, the Click event will be executed, which is the Click event I wrote myself, not the onclickGetParent (). Requestdisallowintercepttouchevent (false); if(downp.x==curp.x && downp.y==curp.y) { return true; }} super.ontouchevent (arg0); //Note that this sentence cannot return super.ontouchevent (arg0), otherwise triggers the parent slide return true; } }
Android Viewpager nested Viewpager sliding conflict processing method