场景: viewpager嵌套侧滑删除的listview(如SwipeMenuListView),当在滑动在SwipeMenuListView的viewpager页时,两者滑动冲突
解决:自定义listview类继承SwipeMenuListView,重写touch的各个事件,拦截父类点击事件
public class MySwipMenuLv extends SwipeMenuListView{ private ViewGroup parent; public MySwipMenuLv(Context context, AttributeSet attrs) { super(context, attrs); } public void setNestedpParent(ViewGroup parent) { this.parent = parent; } @Override public boolean dispatchTouchEvent(MotionEvent ev) { if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } return super.dispatchTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent arg0) { if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(arg0); } @Override public boolean onTouchEvent(MotionEvent arg0) { if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } return super.onTouchEvent(arg0); } }
代码中:
通过setNestedpParent()方法传入MySwipMenuLv的父类对象(也就是viewpager)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。