Skip to content

Commit

Permalink
2016 12 09,fix ListView快速滑动快速删除时,偶现菜单不消失的bug。
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxutong committed Dec 9, 2016
1 parent e1ceee9 commit f223d2c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion swipemenulib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@
* 2016 11 14 fix,微小位移的move不回回弹的bug
* 2016 11 18,fix 当ItemView存在高度可变的情况
* 2016 12 07,fix 禁止侧滑时(isSwipeEnable false),点击事件不受干扰。
* 2016 12 09,fix ListView快速滑动快速删除时,偶现菜单不消失的bug。
* Created by zhangxutong .
* Date: 16/04/24
*/
public class SwipeMenuLayout extends ViewGroup {
private static final String TAG = "zxt";
private static final String TAG = "zxt/SwipeMenuLayout";

private int mScaleTouchSlop;//为了处理单击事件的冲突
private int mMaxVelocity;//计算滑动速度用
Expand Down Expand Up @@ -495,6 +496,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
private boolean isExpand;//代表当前是否是展开状态 2016 11 03 add

public void smoothExpand() {
//Log.d(TAG, "smoothExpand() called" + this);
/*mScroller.startScroll(getScrollX(), 0, mRightMenuWidths - getScrollX(), 0);
invalidate();*/
//展开就加入ViewCache:
Expand All @@ -505,9 +507,7 @@ public void smoothExpand() {
mContentView.setLongClickable(false);
}

if (mCloseAnim != null && mCloseAnim.isRunning()) {
mCloseAnim.cancel();
}
cancelAnim();
mExpandAnim = ValueAnimator.ofInt(getScrollX(), isLeftSwipe ? mRightMenuWidths : -mRightMenuWidths);
mExpandAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
Expand All @@ -525,10 +525,23 @@ public void onAnimationEnd(Animator animation) {
mExpandAnim.setDuration(300).start();
}

/**
* 每次执行动画之前都应该先取消之前的动画
*/
private void cancelAnim() {
if (mCloseAnim != null && mCloseAnim.isRunning()) {
mCloseAnim.cancel();
}
if (mExpandAnim != null && mExpandAnim.isRunning()) {
mExpandAnim.cancel();
}
}

/**
* 平滑关闭
*/
public void smoothClose() {
//Log.d(TAG, "smoothClose() called" + this);
/* mScroller.startScroll(getScrollX(), 0, -getScrollX(), 0);
invalidate();*/
mViewCache = null;
Expand All @@ -538,9 +551,7 @@ public void smoothClose() {
mContentView.setLongClickable(true);
}

if (mExpandAnim != null && mExpandAnim.isRunning()) {
mExpandAnim.cancel();
}
cancelAnim();
mCloseAnim = ValueAnimator.ofInt(getScrollX(), 0);
mCloseAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
Expand Down Expand Up @@ -628,9 +639,7 @@ public void computeScroll() {
public void quickClose() {
if (this == mViewCache) {
//先取消展开动画
if (null != mExpandAnim && mExpandAnim.isRunning()) {
mExpandAnim.cancel();
}
cancelAnim();
mViewCache.scrollTo(0, 0);//关闭
mViewCache = null;
}
Expand Down
3 changes: 0 additions & 3 deletions swipemenulib/src/main/res/values/strings.xml

This file was deleted.

0 comments on commit f223d2c

Please sign in to comment.