4
4
import android .database .DataSetObserver ;
5
5
import android .graphics .Rect ;
6
6
import android .util .AttributeSet ;
7
- import android .util .Log ;
8
7
import android .util .SparseArray ;
9
8
import android .view .MotionEvent ;
10
9
import android .view .View ;
11
10
import android .view .ViewConfiguration ;
12
- import android .view .ViewGroup ;
13
- import android .view .View .MeasureSpec ;
14
11
import android .view .animation .AccelerateInterpolator ;
15
12
import android .widget .FrameLayout ;
16
13
import android .widget .ListAdapter ;
@@ -107,7 +104,6 @@ && getChildCount() < mMaxVisible) {
107
104
final View view = mListAdapter .getView (mNextAdapterPosition ,
108
105
convertView , this );
109
106
view .setOnClickListener (null );
110
- // view.setOnTouchListener(null);
111
107
viewHolder .put (index , view );
112
108
113
109
// 添加剩余的View时,始终处在最后
@@ -173,17 +169,13 @@ protected void onLayout(boolean changed, int left, int top, int right,
173
169
}
174
170
175
171
float downX , downY ;
176
- boolean remove = false ;
177
172
178
173
@ Override
179
174
public boolean onTouchEvent (MotionEvent event ) {
180
175
switch (event .getAction ()) {
181
176
case MotionEvent .ACTION_MOVE :
182
- if (!remove ) {
183
- if (goDown ()) {
184
- downY = -1 ;
185
- remove = true ;
186
- }
177
+ if (goDown ()) {
178
+ downY = -1 ;
187
179
}
188
180
break ;
189
181
}
@@ -195,12 +187,16 @@ public boolean onTouchEvent(MotionEvent event) {
195
187
*/
196
188
private boolean goDown () {
197
189
final View topView = getChildAt (getChildCount () - 1 );
190
+ if (!topView .isClickable ()){
191
+ return false ;
192
+ }
198
193
// topView.getHitRect(topRect); 在4.3以前有bug,用以下方法代替
199
194
topRect = getHitRect (topRect , topView );
200
195
// 如果按下的位置不在顶部视图上,则不移动
201
196
if (!topRect .contains ((int ) downX , (int ) downY )) {
202
197
return false ;
203
198
}
199
+ topView .setClickable (false );
204
200
ViewPropertyAnimator anim = ViewPropertyAnimator
205
201
.animate (topView )
206
202
.translationY (
@@ -210,6 +206,7 @@ private boolean goDown() {
210
206
anim .setListener (new AnimatorListenerAdapter () {
211
207
@ Override
212
208
public void onAnimationEnd (Animator animation ) {
209
+ topView .setClickable (true );
213
210
removeView (topView );
214
211
ensureFull ();
215
212
final int count = getChildCount ();
@@ -245,6 +242,7 @@ public void onAnimationEnd(Animator animation) {
245
242
* @param view
246
243
*/
247
244
private void bringToTop (final View view ) {
245
+ topPosition ++;
248
246
float scaleX = ViewHelper .getScaleX (view ) + ((float ) 1 / mMaxVisible )
249
247
* 0.2f ;
250
248
float tranlateY = ViewHelper .getTranslationY (view ) + itemSpace ;
@@ -253,8 +251,7 @@ private void bringToTop(final View view) {
253
251
.setInterpolator (new AccelerateInterpolator ())
254
252
.setListener (null ).setListener (new AnimatorListenerAdapter () {
255
253
public void onAnimationEnd (Animator animation ) {
256
- topPosition ++;
257
- remove = false ;
254
+
258
255
}
259
256
});
260
257
}
0 commit comments