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

修改了当List中已有一个滑开的item1,此时滑动另一个item,上一个item不关闭的问题。 #143

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 @@ -188,8 +188,8 @@ public boolean onSwipe(MotionEvent event) {
case MotionEvent.ACTION_UP:
if ((isFling || Math.abs(mDownX - event.getX()) > (mMenuView.getWidth() / 2)) &&
Math.signum(mDownX - event.getX()) == mSwipeDirection) {
// open
smoothOpenMenu();
if(state != STATE_OPEN) //判断一下更好
smoothOpenMenu();// open
} else {
// close
smoothCloseMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SwipeMenuListView extends ListView {
private float mDownY;
private int mTouchState;
private int mTouchPosition;
//the last position/上一次点击的位置
private int mOldTouchPosition = -1;
private SwipeMenuLayout mTouchView;
private OnSwipeListener mOnSwipeListener;

Expand Down Expand Up @@ -160,20 +162,34 @@ public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
//int oldPos = mTouchPosition;//this is wrong/这里不能这么写,mTouchPosition与oldPos是永远相等的
//-1是初始值,根据是否等于-1,判断是否第一次按下
if(mOldTouchPosition == -1){//-1 is the original value
mOldTouchPosition = mTouchPosition;
}
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;

mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

if (mTouchPosition == oldPos && mTouchView != null
//在这里mTouchPosition与oldPos是永远相等的,达不到想要的结果,因为它俩对应一个MotionEvent
/*if (mTouchPosition == oldPos && mTouchView != null
&& mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}*/
//这里的mOldTouchPosition才是上一次的position
if (mTouchPosition == mOldTouchPosition && mTouchView != null
&& mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}

//当位置不同时,更新mOldTouchPosition
if(mOldTouchPosition != mTouchPosition){
mOldTouchPosition = mTouchPosition;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());

if (mTouchView != null && mTouchView.isOpen()) {
Expand Down