@@ -655,10 +655,26 @@ public void addOnLayoutListener(OnLayout l) {
655
655
public void removeOnLayoutListener (OnLayout l ) {
656
656
if (mOnLayoutListeners != null ) mOnLayoutListeners .remove (l );
657
657
}
658
+ public void clearDragEdge (){
659
+ mDragEdges .clear ();
660
+ }
661
+ public void setDrag (DragEdge dragEdge , int childId ){
662
+ clearDragEdge ();
663
+ addDrag (dragEdge , childId );
664
+ }
665
+ public void setDrag (DragEdge dragEdge , View child ){
666
+ clearDragEdge ();
667
+ addDrag (dragEdge , child );
668
+ }
669
+ public void addDrag (DragEdge dragEdge , int childId ){
670
+ addDrag (dragEdge , findViewById (childId ), null );
671
+ }
658
672
public void addDrag (DragEdge dragEdge , View child ){
659
673
addDrag (dragEdge , child , null );
660
674
}
661
675
public void addDrag (DragEdge dragEdge , View child , ViewGroup .LayoutParams params ){
676
+ if (child ==null ) return ;
677
+
662
678
if (params ==null ){
663
679
params = generateDefaultLayoutParams ();
664
680
}
@@ -679,6 +695,7 @@ public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params
679
695
}
680
696
@ Override
681
697
public void addView (View child , int index , ViewGroup .LayoutParams params ) {
698
+ if (child ==null ) return ;
682
699
int gravity = Gravity .NO_GRAVITY ;
683
700
try {
684
701
gravity = (Integer ) params .getClass ().getField ("gravity" ).get (params );
@@ -710,7 +727,7 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
710
727
}
711
728
}
712
729
}
713
- if (child == null || child .getParent () == this ){
730
+ if (child .getParent () == this ){
714
731
return ;
715
732
}
716
733
super .addView (child , index , params );
@@ -1429,9 +1446,10 @@ private int dp2px(float dp) {
1429
1446
}
1430
1447
1431
1448
1432
- /**Deprecated, use {@link #addDrag (DragEdge, View)} */
1449
+ /**Deprecated, use {@link #setDrag (DragEdge, View)} */
1433
1450
@ Deprecated
1434
1451
public void setDragEdge (DragEdge dragEdge ) {
1452
+ clearDragEdge ();
1435
1453
if (getChildCount () >= 2 ){
1436
1454
mDragEdges .put (dragEdge , getChildAt (getChildCount ()-2 ));
1437
1455
}
@@ -1455,9 +1473,10 @@ public List<DragEdge> getDragEdges() {
1455
1473
return new ArrayList <DragEdge >(mDragEdges .keySet ());
1456
1474
}
1457
1475
1458
- /**Deprecated, use {@link #addDrag (DragEdge, View)} */
1476
+ /**Deprecated, use {@link #setDrag (DragEdge, View)} */
1459
1477
@ Deprecated
1460
1478
public void setDragEdges (List <DragEdge > dragEdges ) {
1479
+ clearDragEdge ();
1461
1480
for (int i = 0 , size = Math .min (dragEdges .size (), getChildCount () - 1 ); i < size ; i ++) {
1462
1481
DragEdge dragEdge = dragEdges .get (i );
1463
1482
mDragEdges .put (dragEdge , getChildAt (i ));
@@ -1472,6 +1491,7 @@ public void setDragEdges(List<DragEdge> dragEdges) {
1472
1491
/**Deprecated, use {@link #addDrag(DragEdge, View)} */
1473
1492
@ Deprecated
1474
1493
public void setDragEdges (DragEdge ... mDragEdges ) {
1494
+ clearDragEdge ();
1475
1495
setDragEdges (Arrays .asList (mDragEdges ));
1476
1496
}
1477
1497
/**
0 commit comments