1
1
package com .wangxiandeng .swipecardrecyclerview ;
2
2
3
+ import android .animation .Animator ;
3
4
import android .animation .TimeInterpolator ;
4
5
import android .animation .ValueAnimator ;
5
6
import android .app .Activity ;
@@ -92,6 +93,7 @@ public boolean onTouchEvent(MotionEvent e) {
92
93
93
94
/**
94
95
* 更新下一个View的宽高
96
+ *
95
97
* @param factor
96
98
*/
97
99
private void updateNextItem (double factor ) {
@@ -107,7 +109,8 @@ private void updateNextItem(double factor) {
107
109
}
108
110
109
111
/**
110
- *手指抬起时触发动画
112
+ * 手指抬起时触发动画
113
+ *
111
114
* @param view
112
115
*/
113
116
private void touchUp (final View view ) {
@@ -119,11 +122,11 @@ private void touchUp(final View view) {
119
122
targetY = mTopViewY ;
120
123
} else if (view .getX () - mTopViewX > mBorder ) {
121
124
del = true ;
122
- targetX = getScreenWidth ()* 2 ;
125
+ targetX = getScreenWidth () * 2 ;
123
126
mRemovedListener .onRightRemoved ();
124
127
} else {
125
128
del = true ;
126
- targetX = -view .getWidth ()- getScreenWidth ();
129
+ targetX = -view .getWidth () - getScreenWidth ();
127
130
mRemovedListener .onLeftRemoved ();
128
131
}
129
132
View animView = view ;
@@ -138,11 +141,36 @@ private void touchUp(final View view) {
138
141
interpolator = new OvershootInterpolator ();
139
142
}
140
143
final boolean finalDel = del ;
144
+ final View finalAnimView = animView ;
141
145
animView .animate ()
142
146
.setDuration (500 )
143
147
.x (targetX )
144
148
.y (targetY )
145
149
.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
+ })
146
174
.setUpdateListener (new ValueAnimator .AnimatorUpdateListener () {
147
175
@ Override
148
176
public void onAnimationUpdate (ValueAnimator animation ) {
@@ -162,6 +190,7 @@ TypedValue.COMPLEX_UNIT_DIP, dip, getContext().getResources().getDisplayMetrics(
162
190
163
191
/**
164
192
* 计算View退场时的纵坐标,简单的线性计算
193
+ *
165
194
* @param x1
166
195
* @param y1
167
196
* @param x2
0 commit comments