@@ -61,6 +61,8 @@ public interface OnViewSwapListener {
61
61
62
62
private OnViewSwapListener swapListener ;
63
63
64
+ private LayoutTransition layoutTransition ;
65
+
64
66
/**
65
67
* Mapping from child index to drag-related info container.
66
68
* Presence of mapping implies the child can be dragged, and is considered for swaps with the
@@ -262,6 +264,11 @@ public void addDragView(View child, View dragHandle, int index) {
262
264
* Makes the child a candidate for dragging. Must be an existing child of this layout.
263
265
*/
264
266
public void setViewDraggable (View child , View dragHandle ) {
267
+ if (null == child || null == dragHandle ) {
268
+ throw new IllegalArgumentException (
269
+ "Draggable children and their drag handles must not be null." );
270
+ }
271
+
265
272
if (this == child .getParent ()) {
266
273
dragHandle .setOnTouchListener (new DragHandleOnTouchListener (child ));
267
274
draggableChildren .put (indexOfChild (child ), new DraggableChild ());
@@ -296,6 +303,12 @@ public void removeDragView(View child) {
296
303
}
297
304
}
298
305
306
+ @ Override
307
+ public void removeAllViews () {
308
+ super .removeAllViews ();
309
+ draggableChildren .clear ();
310
+ }
311
+
299
312
/**
300
313
* If this layout is within a {@link android.widget.ScrollView}, register it here so that it
301
314
* can be scrolled during item drags.
@@ -351,6 +364,13 @@ private void startDetectingDrag(View child) {
351
364
}
352
365
353
366
private void startDrag () {
367
+ // remove layout transition, it conflicts with drag animation
368
+ // we will restore it after drag animation end, see onDragStop()
369
+ layoutTransition = getLayoutTransition ();
370
+ if (layoutTransition != null ) {
371
+ setLayoutTransition (null );
372
+ }
373
+
354
374
draggedItem .onDragStart ();
355
375
requestDisallowInterceptTouchEvent (true );
356
376
}
@@ -392,6 +412,11 @@ public void onAnimationEnd(Animator animation) {
392
412
393
413
if (null != dragTopShadowDrawable ) dragTopShadowDrawable .setAlpha (255 );
394
414
dragBottomShadowDrawable .setAlpha (255 );
415
+
416
+ // restore layout transition
417
+ if (layoutTransition != null && getLayoutTransition () == null ) {
418
+ setLayoutTransition (layoutTransition );
419
+ }
395
420
}
396
421
});
397
422
draggedItem .settleAnimation .start ();
@@ -726,4 +751,4 @@ private static Bitmap getBitmapFromView(View view) {
726
751
view .draw (canvas );
727
752
return bitmap ;
728
753
}
729
- }
754
+ }
0 commit comments