1111import android .view .ViewGroup ;
1212import android .view .ViewParent ;
1313import android .widget .AdapterView ;
14+ import android .widget .FrameLayout ;
1415
1516import java .util .ArrayList ;
1617import java .util .HashMap ;
1718import java .util .List ;
1819import java .util .Map ;
1920
20- public class SwipeLayout extends ViewGroup {
21+ public class SwipeLayout extends FrameLayout {
2122
2223 private ViewDragHelper mDragHelper ;
2324
@@ -588,57 +589,12 @@ void layoutLayDown(){
588589
589590 @ Override
590591 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
591- int widthMode = MeasureSpec .getMode (widthMeasureSpec );
592- int heightMode = MeasureSpec .getMode (heightMeasureSpec );
593- int widthSize = MeasureSpec .getSize (widthMeasureSpec );
594- int heightSize = MeasureSpec .getSize (heightMeasureSpec );
595-
596- int width , height ;
597-
598- if (heightMode == MeasureSpec .UNSPECIFIED )
599- heightSize = Integer .MAX_VALUE ;
600-
601- if (widthMode == MeasureSpec .UNSPECIFIED )
602- widthSize = Integer .MAX_VALUE ;
603-
604- measure (getSurfaceView (), widthSize , heightSize );
605- measure (getBottomView (), widthSize , heightSize );
606-
592+ super .onMeasure (widthMeasureSpec , heightMeasureSpec );
593+
607594 if (mDragEdge == DragEdge .Left || mDragEdge == DragEdge .Right )
608595 mDragDistance = getBottomView ().getMeasuredWidth ();
609596 else
610597 mDragDistance = getBottomView ().getMeasuredHeight ();
611-
612- width = Math .max (getSurfaceView ().getMeasuredWidth (), getBottomView ().getMeasuredWidth ());
613- height = Math .max (getBottomView ().getMeasuredHeight (), getBottomView ().getMeasuredHeight ());
614-
615- setMeasuredDimension (width , height );
616- }
617-
618- private void measure (View child , int maxWidth , int maxHeight ){
619- LayoutParams lp = child .getLayoutParams ();
620- int childWidthSpec , childHeightSpec ;
621- if (lp .width == LayoutParams .WRAP_CONTENT ){
622- childWidthSpec = MeasureSpec .makeMeasureSpec (maxWidth , MeasureSpec .AT_MOST );
623- }else if (lp .width == LayoutParams .MATCH_PARENT ){
624- childWidthSpec = MeasureSpec .makeMeasureSpec (maxWidth , MeasureSpec .EXACTLY );
625- }else {
626- childWidthSpec = MeasureSpec .makeMeasureSpec (Math .min (maxWidth , lp .width ), MeasureSpec .EXACTLY );
627- }
628-
629- if (lp .height == LayoutParams .WRAP_CONTENT ){
630- childHeightSpec = MeasureSpec .makeMeasureSpec (maxHeight , MeasureSpec .AT_MOST );
631- }else if (lp .height == LayoutParams .MATCH_PARENT ) {
632- if (maxHeight == Integer .MAX_VALUE ){
633- maxHeight = dp2px (80 );
634- }
635- childHeightSpec = MeasureSpec .makeMeasureSpec (maxHeight , MeasureSpec .EXACTLY );
636- }else {
637- childHeightSpec = MeasureSpec .makeMeasureSpec (Math .min (maxHeight , lp .height ), MeasureSpec .EXACTLY );
638- }
639-
640- child .measure (childWidthSpec , childHeightSpec );
641-
642598 }
643599
644600 @ Override
@@ -1058,4 +1014,4 @@ private Rect computeBottomLayDown(DragEdge dragEdge){
10581014 private int dp2px (float dp ){
10591015 return (int ) (dp * getContext ().getResources ().getDisplayMetrics ().density + 0.5f );
10601016 }
1061- }
1017+ }
0 commit comments