In vertical recyclerview nested horizontal Recyclerview, if the vertical Recyclerview has a drop-down refresh function, then the internal horizontal recyclerview lateral sliding experience will be very poor. (Only the pure transverse sliding, can slide the internal transverse recyclerview, otherwise the sliding event will affect the Drop-down refresh), add interception judgment.
public class Myswiperefreshlayout extends Swiperefreshlayout {private Boolean misvpdragger;
private final int mtouchslop;
private float Starty;
private float startx;
Public Myswiperefreshlayout {Super (context);
Mtouchslop = Viewconfiguration.get (context). Getscaledtouchslop ();
Public Myswiperefreshlayout (context, AttributeSet attrs) {Super (context, attrs);
Mtouchslop = Viewconfiguration.get (context). Getscaledtouchslop ();
@Override public boolean onintercepttouchevent (motionevent ev) {int action = ev.getaction ();
Switch (action) {case Motionevent.action_down://Record the position of the finger Starty = Ev.gety ();
StartX = Ev.getx ();
Initialize token Misvpdragger = false;
Break
Case Motionevent.action_move://If Viewpager is dragging, then do not intercept its event, direct return false; if (Misvpdragger) {
return false;
//get current finger position float EndY = ev.gety (); float EndX = Ev.getx ();
float Distancex = Math.Abs (ENDX-STARTX);
float Distancey = Math.Abs (Endy-starty);
If the x-axis displacement is greater than the y-axis displacement, the event is given to Viewpager processing.
if (Distancex > Mtouchslop && Distancex > Distancey) {Misvpdragger = true;
return false;
} break;
Case MotionEvent.ACTION_UP:case Motionevent.action_cancel://Initialize tag Misvpdragger = false;
Break
//If the y-axis displacement is greater than the X axis, the event is given to swiperefreshlayout processing.
return super.onintercepttouchevent (EV);
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.