之前新项目里需要用到下拉刷新,懒得用第三方,然后想到的是SwipeRefreshLayout,于是就开干
下面贴段代码:
public classLXC_SwipeRefreshLayoutextendsSwipeRefreshLayout {
publicLXC_SwipeRefreshLayout(Context context,AttributeSet attrs) {
super(context,attrs);
}
publicLXC_SwipeRefreshLayout(Context context) {
super(context);
}
floatY=0;
floatX=0;
@Override
public booleanonInterceptTouchEvent(MotionEvent ev) {
final intaction = MotionEventCompat.getActionMasked(ev);
switch(action) {
caseMotionEvent.ACTION_DOWN:
Y= ev.getRawY();
X=ev.getRawX();
return super.onInterceptTouchEvent(ev);
caseMotionEvent.ACTION_MOVE:
if((ev.getRawX()-X)>0) {
//右划
if((ev.getRawX() -X) > (ev.getRawY() -Y)) {
return false;
}else{
return super.onInterceptTouchEvent(ev);
}
}else{
//左划
if(X-(ev.getRawX()) > (ev.getRawY() -Y)) {
return false;
}else{
return super.onInterceptTouchEvent(ev);
}
}
caseMotionEvent.ACTION_UP:
Y=0;
X=0;
return super.onInterceptTouchEvent(ev);
}
return false;
}
}