在開發中各種滑動布局的view如ScrollView,ListView等非常常用,但是你也會發現各種奇怪問題産生。網上的解決方法有很多種,但是雜而不全,根據個人經驗現在列出常見問題以及代碼最少最簡單的解決方法,首先你要了解事件的分發機制及事件沖突,這裡不再贅述。(其他繼承自AbsListView的類也适用,包括ExpandableListView、GridView等等)
-
ScrollView嵌套ListView沖突問題的最優解決方案
ScrollView嵌套ListVew或者GridView等很常用,下面來說解決版本 問題一 : 嵌套在 ScrollView的 ListVew資料顯示不全,我遇到的是最多隻顯示兩條已有的資料。 解決辦法:重寫 ListVew或者 GridView,網上還有很多若幹解決辦法,但是都不好用或者很複雜。 問題二 、打開套有 ListVew的 ScrollView的頁面布局 預設 起始位置不是最頂部。 解決辦法有兩種都挺好用: 一是把套在裡面的Gridview 或者 ListVew 不讓擷取焦點即可。 gridview.setFocusable(false); listview.setFocusable(false); 注意:在xml布局裡面設定android:focusable=“false”不生效 方法二:網上還查到說可以設定myScrollView.smoothScrollTo(0,0); |
-
- 看錯誤的布局代碼:
- <ScrollView
- android:id="@+id/act_solution_1_sv"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="\nListView上方資料\n" />
- <ListView
- android:id="@+id/act_solution_1_lv"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </ListView>
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="\nListView下方資料\n" />
- </LinearLayout>
- </ScrollView>
- ScrollView中隻能放一個控件,一般都放LinearLayout,orientation屬性值為vertical。
- 在LinearLayout中放需要呈現的内容。ListView也在其中,ListView的高度設為适應自身内容(wrap_content
- 原因就是scroll事件的消費處理以及ListView控件的高度設定問題
-
ViewPager和ScrollView嵌套滾動問題解決方案
-
- 嵌套是ViewPager-->ScrollView-->ViewPager.
- public class HorizontalInnerViewPager extends ViewPager {
- /** 觸摸時按下的點 **/
- PointF downP = new PointF();
- /** 觸摸時目前的點 **/
- PointF curP = new PointF();
- /** 自定義手勢**/
- private GestureDetector mGestureDetector;
- public HorizontalInnerViewPager(Context context, AttributeSet attrs) {
- super(context, attrs);
- mGestureDetector = new GestureDetector(context, new XScrollDetector());
- }
- public HorizontalInnerViewPager(Context context) {
- super(context);
- mGestureDetector = new GestureDetector(context, new XScrollDetector());
- }
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- return super.onInterceptTouchEvent(ev);//default
- //當攔截觸摸事件到達此位置的時候,傳回true,
- //說明将onTouch攔截在此控件,進而執行此控件的onTouchEvent
- // return true;
- //接近水準滑動時子控件處理該事件,否則交給父控件處理
- // return mGestureDetector.onTouchEvent(ev);
- }
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- //每次進行onTouch事件都記錄目前的按下的坐标
- curP.x = ev.getX();
- curP.y = ev.getY();
- if(ev.getAction() == MotionEvent.ACTION_DOWN){
- //記錄按下時候的坐标
- //切記不可用 downP = curP ,這樣在改變curP的時候,downP也會改變
- downP.x = ev.getX();
- downP.y = ev.getY();
- //此句代碼是為了通知他的父ViewPager現在進行的是本控件的操作,不要對我的操作進行幹擾
- getParent().requestDisallowInterceptTouchEvent(true);
- }
- if(ev.getAction() == MotionEvent.ACTION_MOVE){
- float distanceX = curP.x - downP.x;
- float distanceY = curP.y - downP.y;
- //接近水準滑動,ViewPager控件捕獲手勢,水準滾動
- if(Math.abs(distanceX) > Math.abs(distanceY)){
- //此句代碼是為了通知他的父ViewPager現在進行的是本控件的操作,不要對我的操作進行幹擾
- getParent().requestDisallowInterceptTouchEvent(true);
- }else{
- //接近垂直滑動,交給父控件處理
- getParent().requestDisallowInterceptTouchEvent(false);
- }
- }
- return super.onTouchEvent(ev);
- }
- private class XScrollDetector extends GestureDetector.SimpleOnGestureListener{
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- // return super.onScroll(e1, e2, distanceX, distanceY);
- //接近水準滑動時子控件處理該事件,否則交給父控件處理
- return (Math.abs(distanceX) > Math.abs(distanceY));
- }
- }
- }
-
ScrollView裡嵌套ScrollView
-
- 兩個相同方向的ScrollView是不能嵌套的,是以盡量避免這種情況; 如果不能避免,則看下面
- 目前做的這個隻支援兩個ScrollView嵌套,兩個以上還有待改進,能套兩個就已經能滿足很多需求了目前為縱向scrollview的支援.直接看代碼:
- public class InnerScrollView extends ScrollView {
- /**
- */
- public ScrollView parentScrollView;
- public InnerScrollView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- private int lastScrollDelta = 0;
- public void resume() {
- overScrollBy(0, -lastScrollDelta, 0, getScrollY(), 0, getScrollRange(), 0, 0, true);
- lastScrollDelta = 0;
- }
- int mTop = 10;
- /**
- * 将targetView滾到最頂端
- */
- public void scrollTo(View targetView) {
- int oldScrollY = getScrollY();
- int top = targetView.getTop() - mTop;
- int delatY = top - oldScrollY;
- lastScrollDelta = delatY;
- overScrollBy(0, delatY, 0, getScrollY(), 0, getScrollRange(), 0, 0, true);
- }
- private int getScrollRange() {
- int scrollRange = 0;
- if (getChildCount() > 0) {
- View child = getChildAt(0);
- scrollRange = Math.max(0, child.getHeight() - (getHeight()));
- }
- return scrollRange;
- }
- int currentY;
- @Override
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- if (parentScrollView == null) {
- return super.onInterceptTouchEvent(ev);
- } else {
- if (ev.getAction() == MotionEvent.ACTION_DOWN) {
- // 将父scrollview的滾動事件攔截
- currentY = (int)ev.getY();
- setParentScrollAble(false);
- return super.onInterceptTouchEvent(ev);
- } else if (ev.getAction() == MotionEvent.ACTION_UP) {
- // 把滾動事件恢複給父Scrollview
- setParentScrollAble(true);
- } else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
- }
- }
- return super.onInterceptTouchEvent(ev);
- }
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- View child = getChildAt(0);
- if (parentScrollView != null) {
- if (ev.getAction() == MotionEvent.ACTION_MOVE) {
- int height = child.getMeasuredHeight();
- height = height - getMeasuredHeight();
- // System.out.println("height=" + height);
- int scrollY = getScrollY();
- // System.out.println("scrollY" + scrollY);
- int y = (int)ev.getY();
- // 手指向下滑動
- if (currentY < y) {
- if (scrollY <= 0) {
- // 如果向下滑動到頭,就把滾動交給父Scrollview
- setParentScrollAble(true);
- return false;
- } else {
- setParentScrollAble(false);
- }
- } else if (currentY > y) {
- if (scrollY >= height) {
- // 如果向上滑動到頭,就把滾動交給父Scrollview
- setParentScrollAble(true);
- return false;
- } else {
- setParentScrollAble(false);
- }
- }
- currentY = y;
- }
- }
- return super.onTouchEvent(ev);
- }
- /**
- * 是否把滾動事件交給父scrollview
- *
- * @param flag
- */
- private void setParentScrollAble(boolean flag) {
- parentScrollView.requestDisallowInterceptTouchEvent(!flag);
- }
- }
-
RecyclerView嵌套滾動問題
在 Android 應用中,大部分情況下都會使用一個垂直滾動的 View 來顯示内容(比如 ListView、RecyclerView 等)。但是有時候你還希望垂直滾動的View 裡面的内容可以水準滾動。如果直接在垂直滾動的 View 裡面使用水準滾動的 View,則滾動操作并不是很流暢。
比如下圖中的示例:
為什麼會出現這個問題呢?
上圖中的布局為一個 RecyclerView 使用的是垂直滾動的 LinearLayoutManager 布局管理器,而裡面每個 Item 為另外一個 RecyclerView 使用的是水準滾動的 LinearLayoutManager。而在 Android系統的事件分發 中,即使最上層的 View 隻能垂直滾動,當使用者水準拖動的時候,最上層的 View 依然會攔截點選事件。下面是 RecyclerView.java 中 onInterceptTouchEvent 的相關代碼:
注意上面的 if 判斷:@Override public boolean onInterceptTouchEvent(MotionEvent e) { ... switch (action) { case MotionEvent.ACTION_DOWN: ... case MotionEvent.ACTION_MOVE: { ... if (mScrollState != SCROLL_STATE_DRAGGING) { boolean startScroll = false; if (canScrollHorizontally && Math.abs(dx) > mTouchSlop) { ... startScroll = true; } if (canScrollVertically && Math.abs(dy) > mTouchSlop) { ... startScroll = true; } if (startScroll) { setScrollState(SCROLL_STATE_DRAGGING); } } } break; ... } return mScrollState == SCROLL_STATE_DRAGGING; }
if(canScrollVertically && Math.abs(dy) > mTouchSlop) {...}
RecyclerView 并沒有判斷使用者拖動的角度, 隻是用來判斷拖動的距離是否大于滾動的最小尺寸。 如果是一個隻能垂直滾動的 View,這樣實作是沒有問題的。如果我們在裡面再放一個 水準滾動的 RecyclerView ,則就出現問題了。
可以通過如下的方式來修複該問題:
下面是一個完整的實作 BetterRecyclerView.java :if(canScrollVertically && Math.abs(dy) > mTouchSlop && (canScrollHorizontally || Math.abs(dy) > Math.abs(dx))) {...}
public class BetterRecyclerView extends RecyclerView{ private static final int INVALID_POINTER = -; private int mScrollPointerId = INVALID_POINTER; private int mInitialTouchX, mInitialTouchY; private int mTouchSlop; public BetterRecyclerView(Contextcontext) { this(context, null); } public BetterRecyclerView(Contextcontext, @Nullable AttributeSetattrs) { this(context, attrs, ); } public BetterRecyclerView(Contextcontext, @Nullable AttributeSetattrs, int defStyle) { super(context, attrs, defStyle); final ViewConfigurationvc = ViewConfiguration.get(getContext()); mTouchSlop = vc.getScaledTouchSlop(); } @Override public void setScrollingTouchSlop(int slopConstant) { super.setScrollingTouchSlop(slopConstant); final ViewConfigurationvc = ViewConfiguration.get(getContext()); switch (slopConstant) { case TOUCH_SLOP_DEFAULT: mTouchSlop = vc.getScaledTouchSlop(); break; case TOUCH_SLOP_PAGING: mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(vc); break; default: break; } } @Override public boolean onInterceptTouchEvent(MotionEvent e) { final int action = MotionEventCompat.getActionMasked(e); final int actionIndex = MotionEventCompat.getActionIndex(e); switch (action) { case MotionEvent.ACTION_DOWN: mScrollPointerId = MotionEventCompat.getPointerId(e, ); mInitialTouchX = (int) (e.getX() + ); mInitialTouchY = (int) (e.getY() + ); return super.onInterceptTouchEvent(e); case MotionEventCompat.ACTION_POINTER_DOWN: mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex); mInitialTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + ); mInitialTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + ); return super.onInterceptTouchEvent(e); case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId); if (index < ) { return false; } final int x = (int) (MotionEventCompat.getX(e, index) + ); final int y = (int) (MotionEventCompat.getY(e, index) + ); if (getScrollState() != SCROLL_STATE_DRAGGING) { final int dx = x - mInitialTouchX; final int dy = y - mInitialTouchY; final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally(); final boolean canScrollVertically = getLayoutManager().canScrollVertically(); boolean startScroll = false; if (canScrollHorizontally && Math.abs(dx) > mTouchSlop && (Math.abs(dx) >= Math.abs(dy) || canScrollVertically)) { startScroll = true; } if (canScrollVertically && Math.abs(dy) > mTouchSlop && (Math.abs(dy) >= Math.abs(dx) || canScrollHorizontally)) { startScroll = true; } return startScroll && super.onInterceptTouchEvent(e); } return super.onInterceptTouchEvent(e); } default: return super.onInterceptTouchEvent(e); } } }
其他問題
當使用者快速滑動(fling)RecyclerView 的時候, RecyclerView 需要一段時間來确定其最終位置。 如果使用者在快速滑動一個子的水準 RecyclerView,在子 RecyclerView 還在滑動的過程中,如果使用者垂直滑動,則是無法垂直滑動的。原因是子 RecyclerView 依然處理了這個垂直滑動事件。 是以,在快速滑動後的滾動到靜止的狀态中,子 View 不應該響應滑動事件了,再次看看 RecyclerView 的 onInterceptTouchEvent() 代碼:@Override public boolean onInterceptTouchEvent(MotionEvent e) { ... switch (action) { case MotionEvent.ACTION_DOWN: ... if (mScrollState == SCROLL_STATE_SETTLING) { getParent().requestDisallowInterceptTouchEvent(true); setScrollState(SCROLL_STATE_DRAGGING); } ... } return mScrollState == SCROLL_STATE_DRAGGING; }
可以看到,當 RecyclerView 的狀态為 SCROLL_STATE_SETTLING (快速滑動後到滑動靜止之間的狀态)時, RecyclerView 告訴父控件不要攔截事件。
同樣的,如果隻有一個方向固定,這樣處理是沒問題的。
針對我們這個嵌套的情況,父 RecyclerView 應該隻攔截垂直滾動事件,是以可以這麼修改父 RecyclerView:
下圖為最終的結果:public class FeedRootRecyclerView extends BetterRecyclerView{ public FeedRootRecyclerView(Contextcontext) { this(context, null); } public FeedRootRecyclerView(Contextcontext, @Nullable AttributeSetattrs) { this(context, attrs, ); } public FeedRootRecyclerView(Contextcontext, @Nullable AttributeSetattrs, int defStyle) { super(context, attrs, defStyle); } @Override public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) { /* do nothing */ } }
-
recycleview跟scrollview嵌套問題
scrollview 嵌套recyclerview 時,recyclerview不顯示,這就需要我們自己計算recyclerview的高度,比如:
這中方法适合item高度比較好計算的情形,但要遇到裡面的item高度不一定這就需要我們重寫recyclerview的高度了,以前嵌套listview的時候我們隻需重寫listview 然後重寫- ViewGroup.LayoutParams mParams = recyclerView.getLayoutParams();
- mParams.height = (CommonUtils.getScreenWidthPX(getActivity()) * 480 / 720 + CommonUtils.dipToPixels(40)) * num + CommonUtils.dipToPixels(8);
- mParams.width = CommonUtils.getScreenWidthPX(getActivity());
- recyclerView.setLayoutParams(mParams);
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- // TODO Auto-generated method stub
- int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
- MeasureSpec.AT_MOST);
- super.onMeasure(widthMeasureSpec, expandSpec);
- }
但是這種方法在recyclerview重寫不管用。
我們此時要重寫的的是LinearLayoutManager或GridLayoutManager
- public class FullyLinearLayoutManager extends LinearLayoutManager {
- private static final String TAG = FullyLinearLayoutManager.class.getSimpleName();
- public FullyLinearLayoutManager(Context context) {
- super(context);
- }
- public FullyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
- super(context, orientation, reverseLayout);
- }
- private int[] mMeasuredDimension = new int[2];
- @Override
- public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state,
- int widthSpec, int heightSpec) {
- final int widthMode = View.MeasureSpec.getMode(widthSpec);
- final int heightMode = View.MeasureSpec.getMode(heightSpec);
- final int widthSize = View.MeasureSpec.getSize(widthSpec);
- final int heightSize = View.MeasureSpec.getSize(heightSpec);
- Log.i(TAG, "onMeasure called. \nwidthMode " + widthMode
- + " \nheightMode " + heightSpec
- + " \nwidthSize " + widthSize
- + " \nheightSize " + heightSize
- + " \ngetItemCount() " + getItemCount());
- int width = 0;
- int height = 0;
- for (int i = 0; i < getItemCount(); i++) {
- measureScrapChild(recycler, i,
- View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
- View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
- mMeasuredDimension);
- if (getOrientation() == HORIZONTAL) {
- width = width + mMeasuredDimension[0];
- if (i == 0) {
- height = mMeasuredDimension[1];
- }
- } else {
- height = height + mMeasuredDimension[1];
- if (i == 0) {
- width = mMeasuredDimension[0];
- }
- }
- }
- switch (widthMode) {
- case View.MeasureSpec.EXACTLY:
- width = widthSize;
- case View.MeasureSpec.AT_MOST:
- case View.MeasureSpec.UNSPECIFIED:
- }
- switch (heightMode) {
- case View.MeasureSpec.EXACTLY:
- height = heightSize;
- case View.MeasureSpec.AT_MOST:
- case View.MeasureSpec.UNSPECIFIED:
- }
- setMeasuredDimension(width, height);
- }
- private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
- int heightSpec, int[] measuredDimension) {
- try {
- View view = recycler.getViewForPosition(0);//fix 動态添加時報IndexOutOfBoundsException
- if (view != null) {
- RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
- int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
- getPaddingLeft() + getPaddingRight(), p.width);
- int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
- getPaddingTop() + getPaddingBottom(), p.height);
- view.measure(childWidthSpec, childHeightSpec);
- measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
- measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
- recycler.recycleView(view);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- }
- }
- }
重寫完之後,用就好說了,在adapter的onBindview和平常一樣用就可以了- public class FullyGridLayoutManager extends GridLayoutManager {
- private int mwidth = 0;
- private int mheight = 0;
- public FullyGridLayoutManager(Context context, int spanCount) {
- super(context, spanCount);
- }
- public FullyGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
- super(context, spanCount, orientation, reverseLayout);
- }
- private int[] mMeasuredDimension = new int[2];
- public int getMwidth() {
- return mwidth;
- }
- public void setMwidth(int mwidth) {
- this.mwidth = mwidth;
- }
- public int getMheight() {
- return mheight;
- }
- public void setMheight(int mheight) {
- this.mheight = mheight;
- }
- @Override
- public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
- final int widthMode = View.MeasureSpec.getMode(widthSpec);
- final int heightMode = View.MeasureSpec.getMode(heightSpec);
- final int widthSize = View.MeasureSpec.getSize(widthSpec);
- final int heightSize = View.MeasureSpec.getSize(heightSpec);
- int width = 0;
- int height = 0;
- int count = getItemCount();
- int span = getSpanCount();
- for (int i = 0; i < count; i++) {
- measureScrapChild(recycler, i,
- View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
- View.MeasureSpec.makeMeasureSpec(i, View.MeasureSpec.UNSPECIFIED),
- mMeasuredDimension);
- if (getOrientation() == HORIZONTAL) {
- if (i % span == 0) {
- width = width + mMeasuredDimension[0];
- }
- if (i == 0) {
- height = mMeasuredDimension[1];
- }
- } else {
- if (i % span == 0) {
- height = height + mMeasuredDimension[1];
- }
- if (i == 0) {
- width = mMeasuredDimension[0];
- }
- }
- }
- switch (widthMode) {
- case View.MeasureSpec.EXACTLY:
- width = widthSize;
- case View.MeasureSpec.AT_MOST:
- case View.MeasureSpec.UNSPECIFIED:
- }
- switch (heightMode) {
- case View.MeasureSpec.EXACTLY:
- height = heightSize;
- case View.MeasureSpec.AT_MOST:
- case View.MeasureSpec.UNSPECIFIED:
- }
- setMheight(height);
- setMwidth(width);
- setMeasuredDimension(width, height);
- }
- private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
- int heightSpec, int[] measuredDimension) {
- if (position < getItemCount()) {
- try {
- View view = recycler.getViewForPosition(0);//fix 動态添加時報IndexOutOfBoundsException
- if (view != null) {
- RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
- int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
- getPaddingLeft() + getPaddingRight(), p.width);
- int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
- getPaddingTop() + getPaddingBottom(), p.height);
- view.measure(childWidthSpec, childHeightSpec);
- measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
- measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
- recycler.recycleView(view);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- final FullyGridLayoutManager manager = new FullyGridLayoutManager(context.getActivity(), 3);
- manager.setOrientation(GridLayoutManager.VERTICAL);
- manager.setSmoothScrollbarEnabled(true);
- viewHolder.recyclerView.setLayoutManager(manager);
或者再activity中設定一樣的
此種方法在4.x系統上好用,能顯示滑動也流暢,但是在5.x上雖然顯示正常,但是滑動的時候好像被粘住了,沒有慣性效果。。。。然後郁悶了一下午。。。。
最後解決方法是重寫最外層的Scrollview
-
- **
- * 屏蔽 滑動事件
- * Created by fc on 2015/7/16.
- */
- public class MyScrollview extends ScrollView {
- private int downX;
- private int downY;
- private int mTouchSlop;
- public MyScrollview(Context context) {
- super(context);
- mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
- }
- public MyScrollview(Context context, AttributeSet attrs) {
- super(context, attrs);
- mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
- }
- public MyScrollview(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
- }
- @Override
- public boolean onInterceptTouchEvent(MotionEvent e) {
- int action = e.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- downX = (int) e.getRawX();
- downY = (int) e.getRawY();
- break;
- case MotionEvent.ACTION_MOVE:
- int moveY = (int) e.getRawY();
- if (Math.abs(moveY - downY) > mTouchSlop) {
- return true;
- }
- }
- return super.onInterceptTouchEvent(e);
- }
- }