国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

ViewPager和SlidingPaneLayout的滑動事件沖突解決方法

2019-10-22 18:17:58
字體:
來源:轉載
供稿:網友

問題描述:

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的滑動事件沖突解決方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东丽区| 朝阳市| 北流市| 文昌市| 英德市| 黄浦区| 曲松县| 宿州市| 梨树县| 贵州省| 叶城县| 滁州市| 甘南县| 冷水江市| 牡丹江市| 横峰县| 宿迁市| 通山县| 孝义市| 绥阳县| 哈巴河县| 曲沃县| 兴安县| 清苑县| 阜南县| 龙泉市| 新田县| 淮北市| 涿州市| 澄城县| 阿拉尔市| 壶关县| 布尔津县| 辰溪县| 称多县| 体育| 石狮市| 大埔县| 洛扎县| 汕头市| 东阿县|