Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复一个bug并完全实现了QQ的那种滑动删除效果 #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,18 @@ public boolean onSwipe(MotionEvent event) {
swipe(dis);
break;
case MotionEvent.ACTION_UP:
if ((isFling || Math.abs(mDownX - event.getX()) > (mMenuView.getWidth() / 2)) &&
Math.signum(mDownX - event.getX()) == mSwipeDirection) {
if ((isFling || Math.signum(mDownX - event.getX()) == mSwipeDirection)) {
// open
smoothOpenMenu();
//新添加的内容,防止在已被拉开的item上向拉开的方向滑动然后抬起手指时,
//item有很大几率关闭的问题
if (Math.abs(mDownX - event.getX()) > (mMenuView.getWidth() / 2)) {
smoothOpenMenu();
} else {
//没有item打开时,且滑动距离不满足打开的条件才进行关闭
if (!isOpen()) {
smoothCloseMenu();
}
}
} else {
// close
smoothCloseMenu();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.baoyz.swipemenulistview;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
Expand Down Expand Up @@ -166,15 +165,24 @@ public boolean onTouchEvent(MotionEvent ev) {
mTouchState = TOUCH_STATE_NONE;

mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());

if (mTouchPosition == oldPos && mTouchView != null
&& mTouchView.isOpen()) {
// 新添加的内容,当按下的item不是当前已经打开的item,则关闭已经打开的item,并返回false.
// 不再响应down以后的事件,仿qq效果
if (view instanceof SwipeMenuLayout) {
SwipeMenuLayout touchView = (SwipeMenuLayout) view;
if (!touchView.isOpen()) {
mTouchView.smoothCloseMenu();
return false;
}
}
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}

View view = getChildAt(mTouchPosition - getFirstVisiblePosition());

if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
Expand Down Expand Up @@ -272,7 +280,7 @@ public void smoothOpenMenu(int position) {
}
}

public void smoothCloseMenu(){
public void smoothCloseMenu() {
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
}
Expand Down