You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.gizwits.opensource.appkit.view ;
import android.content.Context ;
import android.support.v4.widget.SwipeRefreshLayout ;
import android.util.AttributeSet ;
import android.view.MotionEvent ;
import android.view.ViewConfiguration ;
public class VerticalSwipeRefreshLayout extends SwipeRefreshLayout {
private int mTouchSlop ;
// 上一次触摸时的X坐标
private float mPrevX ;
public VerticalSwipeRefreshLayout ( Context context , AttributeSet attrs ) {
super ( context , attrs ) ;
// 触发移动事件的最短距离,如果小于这个距离就不触发移动控件
mTouchSlop = ViewConfiguration . get ( context ) . getScaledTouchSlop ( ) ;
}
@Override
public boolean onInterceptTouchEvent ( MotionEvent event ) {
switch ( event . getAction ( ) ) {
case MotionEvent . ACTION_DOWN :
mPrevX = event . getX ( ) ;
break ;
case MotionEvent . ACTION_MOVE :
final float eventX = event . getX ( ) ;
float xDiff = Math . abs ( eventX - mPrevX ) ;
// Log.d("refresh" ,"move----" + eventX + " " + mPrevX + " " +
// mTouchSlop);
// 增加60的容差, 让下拉刷新在竖直滑动时就可以触发
if ( xDiff > mTouchSlop + 60 ) {
return false ;
}
}
return super . onInterceptTouchEvent ( event ) ;
}
}