Skip to content

Commit 5aeff30

Browse files
XiandengWangXiandengWang
authored andcommitted
fix: 动画结束后移除镜像View
1 parent 30f7895 commit 5aeff30

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

app/src/main/java/com/wangxiandeng/swipecardrecyclerview/SwipeCardRecyclerView.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wangxiandeng.swipecardrecyclerview;
22

3+
import android.animation.Animator;
34
import android.animation.TimeInterpolator;
45
import android.animation.ValueAnimator;
56
import android.app.Activity;
@@ -92,6 +93,7 @@ public boolean onTouchEvent(MotionEvent e) {
9293

9394
/**
9495
* 更新下一个View的宽高
96+
*
9597
* @param factor
9698
*/
9799
private void updateNextItem(double factor) {
@@ -107,7 +109,8 @@ private void updateNextItem(double factor) {
107109
}
108110

109111
/**
110-
*手指抬起时触发动画
112+
* 手指抬起时触发动画
113+
*
111114
* @param view
112115
*/
113116
private void touchUp(final View view) {
@@ -119,11 +122,11 @@ private void touchUp(final View view) {
119122
targetY = mTopViewY;
120123
} else if (view.getX() - mTopViewX > mBorder) {
121124
del = true;
122-
targetX = getScreenWidth()*2;
125+
targetX = getScreenWidth() * 2;
123126
mRemovedListener.onRightRemoved();
124127
} else {
125128
del = true;
126-
targetX = -view.getWidth()-getScreenWidth();
129+
targetX = -view.getWidth() - getScreenWidth();
127130
mRemovedListener.onLeftRemoved();
128131
}
129132
View animView = view;
@@ -138,11 +141,36 @@ private void touchUp(final View view) {
138141
interpolator = new OvershootInterpolator();
139142
}
140143
final boolean finalDel = del;
144+
final View finalAnimView = animView;
141145
animView.animate()
142146
.setDuration(500)
143147
.x(targetX)
144148
.y(targetY)
145149
.setInterpolator(interpolator)
150+
.setListener(new Animator.AnimatorListener() {
151+
@Override
152+
public void onAnimationStart(Animator animation) {
153+
}
154+
155+
@Override
156+
public void onAnimationEnd(Animator animation) {
157+
if (finalDel) {
158+
try {
159+
mDecorView.removeView(finalAnimView);
160+
} catch (Exception e) {
161+
e.printStackTrace();
162+
}
163+
}
164+
}
165+
166+
@Override
167+
public void onAnimationCancel(Animator animation) {
168+
}
169+
170+
@Override
171+
public void onAnimationRepeat(Animator animation) {
172+
}
173+
})
146174
.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
147175
@Override
148176
public void onAnimationUpdate(ValueAnimator animation) {
@@ -162,6 +190,7 @@ TypedValue.COMPLEX_UNIT_DIP, dip, getContext().getResources().getDisplayMetrics(
162190

163191
/**
164192
* 计算View退场时的纵坐标,简单的线性计算
193+
*
165194
* @param x1
166195
* @param y1
167196
* @param x2

0 commit comments

Comments
 (0)