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

首頁 > 系統(tǒng) > Android > 正文

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

2019-12-12 01:21:25
字體:
供稿:網(wǎng)友

問題描述:

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 贵溪市| 章丘市| 东辽县| 林州市| 唐海县| 澜沧| 湘乡市| 任丘市| 镇赉县| 浏阳市| 安康市| 磐安县| 离岛区| 颍上县| 宝清县| 甘孜| 南皮县| 丘北县| 威信县| 资阳市| 高淳县| 渭南市| 永济市| 当涂县| 黄平县| 抚松县| 安徽省| 通道| 焉耆| 福贡县| 运城市| 徐水县| 乌拉特前旗| 定州市| 华宁县| 扬中市| 汕尾市| 武功县| 天全县| 固原市| 金坛市|