Viewpager of sub-viewpager slide after nesting Viewpager

Source: Internet
Author: User
Tags gety

Viewpager nested Viewpager, the sliding event is not able to respond within the sub-viewpager.

The solution is to customize the subclass Viewpager.

The following code is reproduced, after I test, you can use!!!

Reprint Address: http://blog.csdn.net/leewenjin/article/details/21011841

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 class Childviewpager extends viewpager{

PointF DOWNP = new PointF ();

PointF curp = new PointF ();

Onsingletouchlistener Onsingletouchlistener;

Public Childviewpager (context context, AttributeSet Attrs) {

Super (context, attrs);

TODO auto-generated Constructor stub

}

Public Childviewpager (Context context) {

Super (context);

TODO auto-generated Constructor stub

}

@Override

public boolean onintercepttouchevent (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 boolean ontouchevent (Motionevent arg0) {

TODO auto-generated Method Stub

Each time the Ontouch event is logged, the current pressed coordinates are recorded

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 change

downp.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 operation

GetParent (). 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 operation

GetParent (). 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) {

Onsingletouch ();

return true;

}

}

Return super.ontouchevent (arg0);

}

public void Onsingletouch () {

if (onsingletouchlistener!= null) {

Onsingletouchlistener.onsingletouch ();

}

}

Public interface Onsingletouchlistener {

public void Onsingletouch ();

}

public void Setonsingletouchlistener (Onsingletouchlistener onsingletouchlistener) {

This.onsingletouchlistener = Onsingletouchlistener;

}

}

Viewpager of sub-viewpager slide after nesting Viewpager

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.