ViewPager和SlidingPaneLayout的滑动事件冲突解决方法
更新时间:2018年01月02日 08:55:38 作者:Homilier
下面小编就为大家分享一篇ViewPager和SlidingPaneLayout的滑动事件冲突解决方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
问题描述:
ViewPager和SlidingPaneLayout的滑动事件冲突。
问题分析:
在手指左右滑动时,SlidingPaneLayout会屏蔽ViewPager的滑动事件。
解决办法:
自定义SlidingPaneLayout类
import android.content.Context; import android.support.v4.view.MotionEventCompat; import android.support.v4.widget.SlidingPaneLayout; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewConfiguration; public class PagerEnabledSlidingPaneLayout extends SlidingPaneLayout { private float mInitialMotionX; private float mInitialMotionY; private float mEdgeSlop; public PagerEnabledSlidingPaneLayout(Context context) { this(context, null); } public PagerEnabledSlidingPaneLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } public PagerEnabledSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); ViewConfiguration config = ViewConfiguration.get(context); mEdgeSlop = config.getScaledEdgeSlop(); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { mInitialMotionX = ev.getX(); mInitialMotionY = ev.getY(); break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); if (mInitialMotionX > mEdgeSlop && !isOpen() && canScroll(this, false, Math.round(x - mInitialMotionX), Math.round(x), Math.round(y))) { MotionEvent cancelEvent = MotionEvent.obtain(ev); cancelEvent.setAction(MotionEvent.ACTION_CANCEL); return super.onInterceptTouchEvent(cancelEvent); } } } return super.onInterceptTouchEvent(ev); } }
以上这篇ViewPager和SlidingPaneLayout的滑动事件冲突解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
item高度不同时Recyclerview获取滑动距离的方法
这篇文章主要介绍了item高度不同时Recyclerview获取滑动距离的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-11-11Android ksoap调用webservice批量上传多张图片详解
这篇文章主要介绍了Android ksoap调用webservice批量上传多张图片详解的相关资料,需要的朋友可以参考下2017-02-02仿墨迹天气在Android App中实现自定义zip皮肤更换
这篇文章主要介绍了仿墨迹天气在Android App中实现自定义zip皮肤更换的方法,即让用户可以自行通过自制或者下载的zip皮肤包进行换肤,需要的朋友可以参考下2016-02-02
最新评论