private int measureChildCollapseMargins(View child,int parentWidthMeasureSpec,int widthUsed,int parentHeightMeasureSpec,int heightUsed,int[] collapsingMargins){
  final MarginLayoutParams lp=(MarginLayoutParams)child.getLayoutParams();
  final int leftDiff=lp.leftMargin - collapsingMargins[0];
  final int rightDiff=lp.rightMargin - collapsingMargins[1];
  final int leftMargin=Math.max(0,leftDiff);
  final int rightMargin=Math.max(0,rightDiff);
  final int hMargins=leftMargin + rightMargin;
  collapsingMargins[0]=Math.max(0,-leftDiff);
  collapsingMargins[1]=Math.max(0,-rightDiff);
  final int childWidthMeasureSpec=getChildMeasureSpec(parentWidthMeasureSpec,getPaddingLeft() + getPaddingRight() + hMargins+ widthUsed,lp.width);
  final int childHeightMeasureSpec=getChildMeasureSpec(parentHeightMeasureSpec,getPaddingTop() + getPaddingBottom() + lp.topMargin+ lp.bottomMargin+ heightUsed,lp.height);
  child.measure(childWidthMeasureSpec,childHeightMeasureSpec);
  return child.getMeasuredWidth() + hMargins;
}

private int measureChildCollapseMargins ( View child , int parentWidthMeasureSpec , int widthUsed , int parentHeightMeasureSpec , int heightUsed , int [ ] collapsingMargins ) { final MarginLayoutParams lp = ( MarginLayoutParams ) child . getLayoutParams ( ) ; final int leftDiff = lp . leftMargin - collapsingMargins [ 0 ] ; final int rightDiff = lp . rightMargin - collapsingMargins [ 1 ] ; final int leftMargin = Math . max ( 0 , leftDiff ) ; final int rightMargin = Math . max ( 0 , rightDiff ) ; final int hMargins = leftMargin + rightMargin ; collapsingMargins [ 0 ] = Math . max ( 0 , - leftDiff ) ; collapsingMargins [ 1 ] = Math . max ( 0 , - rightDiff ) ; final int childWidthMeasureSpec = getChildMeasureSpec ( parentWidthMeasureSpec , getPaddingLeft ( ) + getPaddingRight ( ) + hMargins + widthUsed , lp . width ) ; final int childHeightMeasureSpec = getChildMeasureSpec ( parentHeightMeasureSpec , getPaddingTop ( ) + getPaddingBottom ( ) + lp . topMargin + lp . bottomMargin + heightUsed , lp . height ) ; child . measure ( childWidthMeasureSpec , childHeightMeasureSpec ) ; return child . getMeasuredWidth ( ) + hMargins ; }
returns the width + uncollapsed margins
