|
|
@@ -0,0 +1,49 @@
|
|
|
+package com.sheep.gamegroup.util;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.view.MotionEvent;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ljy on 2018/6/1.
|
|
|
+ */
|
|
|
+
|
|
|
+public class SheepSwipeRefreshLayout extends SwipeRefreshLayout {
|
|
|
+
|
|
|
+ private float mDownPosX = 0;
|
|
|
+ private float mDownPosY = 0;
|
|
|
+ public SheepSwipeRefreshLayout(@NonNull Context context) {
|
|
|
+ super(context);
|
|
|
+ }
|
|
|
+
|
|
|
+ public SheepSwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
|
+ super(context, attrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
+ final float x = ev.getX();
|
|
|
+ final float y = ev.getY();
|
|
|
+
|
|
|
+ final int action = ev.getAction();
|
|
|
+ switch (action) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ mDownPosX = x;
|
|
|
+ mDownPosY = y;
|
|
|
+
|
|
|
+ break;
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ final float deltaX = Math.abs(x - mDownPosX);
|
|
|
+ final float deltaY = Math.abs(y - mDownPosY);
|
|
|
+ // 这里是否拦截的判断依据是左右滑动,读者可根据自己的逻辑进行是否拦截
|
|
|
+
|
|
|
+ if (deltaX > deltaY) {// 左右滑动不拦截
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return super.onInterceptTouchEvent(ev);
|
|
|
+ }
|
|
|
+}
|