欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決ViewPager和SlidingPaneLayout的滑動(dòng)事件沖突問(wèn)題

 更新時(shí)間:2018年01月04日 15:47:36   作者:Homilier  
下面小編就為大家分享一篇解決ViewPager和SlidingPaneLayout的滑動(dòng)事件沖突問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

問(wèn)題描述:

ViewPager和SlidingPaneLayout的滑動(dòng)事件沖突。

問(wèn)題分析:

在手指左右滑動(dòng)時(shí),SlidingPaneLayout會(huì)屏蔽ViewPager的滑動(dòng)事件。

解決辦法:

自定義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的滑動(dòng)事件沖突問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論