ViewPager和SlidingPaneLayout的滑动事件冲突 ViewPager和SlidingPaneLayout的滑动事件冲突解决办法
Homilier 人气:0想了解ViewPager和SlidingPaneLayout的滑动事件冲突解决办法的相关内容吗,Homilier在本文为您仔细讲解ViewPager和SlidingPaneLayout的滑动事件冲突的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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的滑动事件冲突解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
加载全部内容