Code fragment for Recyclerview nested sliding conflict resolution in Android _android

Source: Internet
Author: User
Tags abs gety

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.

Related Article

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.