@@ -655,10 +655,26 @@ public void addOnLayoutListener(OnLayout l) {
655655 public void removeOnLayoutListener (OnLayout l ) {
656656 if (mOnLayoutListeners != null ) mOnLayoutListeners .remove (l );
657657 }
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+ }
658672 public void addDrag (DragEdge dragEdge , View child ){
659673 addDrag (dragEdge , child , null );
660674 }
661675 public void addDrag (DragEdge dragEdge , View child , ViewGroup .LayoutParams params ){
676+ if (child ==null ) return ;
677+
662678 if (params ==null ){
663679 params = generateDefaultLayoutParams ();
664680 }
@@ -679,6 +695,7 @@ public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params
679695 }
680696 @ Override
681697 public void addView (View child , int index , ViewGroup .LayoutParams params ) {
698+ if (child ==null ) return ;
682699 int gravity = Gravity .NO_GRAVITY ;
683700 try {
684701 gravity = (Integer ) params .getClass ().getField ("gravity" ).get (params );
@@ -710,7 +727,7 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
710727 }
711728 }
712729 }
713- if (child == null || child .getParent () == this ){
730+ if (child .getParent () == this ){
714731 return ;
715732 }
716733 super .addView (child , index , params );
@@ -1429,9 +1446,10 @@ private int dp2px(float dp) {
14291446 }
14301447
14311448
1432- /**Deprecated, use {@link #addDrag (DragEdge, View)} */
1449+ /**Deprecated, use {@link #setDrag (DragEdge, View)} */
14331450 @ Deprecated
14341451 public void setDragEdge (DragEdge dragEdge ) {
1452+ clearDragEdge ();
14351453 if (getChildCount () >= 2 ){
14361454 mDragEdges .put (dragEdge , getChildAt (getChildCount ()-2 ));
14371455 }
@@ -1455,9 +1473,10 @@ public List<DragEdge> getDragEdges() {
14551473 return new ArrayList <DragEdge >(mDragEdges .keySet ());
14561474 }
14571475
1458- /**Deprecated, use {@link #addDrag (DragEdge, View)} */
1476+ /**Deprecated, use {@link #setDrag (DragEdge, View)} */
14591477 @ Deprecated
14601478 public void setDragEdges (List <DragEdge > dragEdges ) {
1479+ clearDragEdge ();
14611480 for (int i = 0 , size = Math .min (dragEdges .size (), getChildCount () - 1 ); i < size ; i ++) {
14621481 DragEdge dragEdge = dragEdges .get (i );
14631482 mDragEdges .put (dragEdge , getChildAt (i ));
@@ -1472,6 +1491,7 @@ public void setDragEdges(List<DragEdge> dragEdges) {
14721491 /**Deprecated, use {@link #addDrag(DragEdge, View)} */
14731492 @ Deprecated
14741493 public void setDragEdges (DragEdge ... mDragEdges ) {
1494+ clearDragEdge ();
14751495 setDragEdges (Arrays .asList (mDragEdges ));
14761496 }
14771497 /**
0 commit comments