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