Android ViewPage Fix nesting

Source: Internet
Author: User

Child ViewPage Custom

Writing one:

 Public classChildviewpagerextendsviewpager{/**Touch the point you 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 Public Booleanonintercepttouchevent (motionevent arg0) {//TODO auto-generated Method Stub//returns True when the Intercept touch event reaches this position.//instructions to intercept ontouch in this control, and then execute the ontouchevent of this control         return true; } @Override Public Booleanontouchevent (motionevent arg0) {//TODO auto-generated Method Stub//each time the Ontouch event is logged, the current pressed coordinates are recordedcurp.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) {//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 onclick             if(downp.x==curp.x && downp.y==curp.y) {//The current point is equal to the present pointOnsingletouch ();//Click event Callback                 return true; }}return Super. Ontouchevent (arg0); }/*** Click*/      Public voidOnsingletouch () {if(onsingletouchlistener!=NULL) {Onsingletouchlistener.onsingletouch (); }}/*** Create Click event interface *@authorWANPG **/      Public InterfaceOnsingletouchlistener { Public voidOnsingletouch (); } Public voidSetonsingletouchlistener (Onsingletouchlistener onsingletouchlistener) { This. Onsingletouchlistener =Onsingletouchlistener; }}

Two:

 Public classMyviewpagerextendsViewpager { PublicMyviewpager (Context context) {Super(context); }     PublicMyviewpager (Context context, AttributeSet attrs) {Super(context, attrs); } PointF downpoint=NewPointF ();    Onsingletouchlistener Onsingletouchlistener; @Override Public Booleanontouchevent (motionevent evt) {Switch(Evt.getaction ()) { CaseMotionevent.action_down://record the coordinates at the time of the pressDownpoint.x =Evt.getx (); Downpoint.y=evt.gety (); if( This. Getchildcount () > 1) {//with content, more than 1 hours//notifies its parent control that it is now doing the operation of this control and is not allowed to interceptGetParent (). Requestdisallowintercepttouchevent (true); }             Break;  CaseMotionevent.action_move:if( This. Getchildcount () > 1) {//with content, more than 1 hours//notifies its parent control that it is now doing the operation of this control and is not allowed to interceptGetParent (). Requestdisallowintercepttouchevent (true); }             Break;  Casemotionevent.action_up://determine if the coordinates of the press and drop are at a point when up            if(Pointf.length (Evt.getx ()-Downpoint.x, evt.gety ()-Downpoint.y) < (float) 5.0) {Onsingletouch ( This); return true; }             Break; }        return Super. Ontouchevent (EVT); }     Public voidOnsingletouch (View v) {if(Onsingletouchlistener! =NULL) {Onsingletouchlistener.onsingletouch (v); }    }     Public InterfaceOnsingletouchlistener { Public voidOnsingletouch (View v); }     Public voidSetonsingletouchlistener (Onsingletouchlistener onsingletouchlistener) { This. Onsingletouchlistener =Onsingletouchlistener; }}

Android ViewPage Fix nesting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.