Program: 24361
Project: 24361
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override protected void onLayout(boolean changed,int left,int top,int right,int bottom){
  final int count=getChildCount();
  final int parentLeft=mPaddingLeft + mForegroundPaddingLeft;
  final int parentRight=right - left - mPaddingRight- mForegroundPaddingRight;
  final int parentTop=mPaddingTop + mForegroundPaddingTop;
  final int parentBottom=bottom - top - mPaddingBottom- mForegroundPaddingBottom;
  for (int i=0; i < count; i++) {
    final View child=getChildAt(i);
    if (child.getVisibility() != GONE) {
      final LayoutParams lp=(LayoutParams)child.getLayoutParams();
      final int width=child.getMeasuredWidth();
      final int height=child.getMeasuredHeight();
      int childLeft=parentLeft;
      int childTop=parentTop;
      final int gravity=lp.gravity;
      if (gravity != -1) {
        final int horizontalGravity=gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        final int verticalGravity=gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (horizontalGravity) {
case Gravity.LEFT:
          childLeft=parentLeft + lp.leftMargin;
        break;
case Gravity.CENTER_HORIZONTAL:
      childLeft=parentLeft + (parentRight - parentLeft + lp.leftMargin + lp.rightMargin - width) / 2;
    break;
case Gravity.RIGHT:
  childLeft=parentRight - width - lp.rightMargin;
break;
default :
childLeft=parentLeft + lp.leftMargin;
}
switch (verticalGravity) {
case Gravity.TOP:
childTop=parentTop + lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop=parentTop + (parentBottom - parentTop + lp.topMargin + lp.bottomMargin - height) / 2;
break;
case Gravity.BOTTOM:
childTop=parentBottom - height - lp.bottomMargin;
break;
default :
childTop=parentTop + lp.topMargin;
}
}
child.layout(childLeft,childTop,childLeft + width,childTop + height);
}
}
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override protected void onLayout(boolean changed,int left,int top,int right,int bottom){
  final int count=getChildCount();
  final int parentLeft=mPaddingLeft + mForegroundPaddingLeft;
  final int parentRight=right - left - mPaddingRight- mForegroundPaddingRight;
  final int parentTop=mPaddingTop + mForegroundPaddingTop;
  final int parentBottom=bottom - top - mPaddingBottom- mForegroundPaddingBottom;
  mForegroundBoundsChanged=true;
  for (int i=0; i < count; i++) {
    final View child=getChildAt(i);
    if (child.getVisibility() != GONE) {
      final LayoutParams lp=(LayoutParams)child.getLayoutParams();
      final int width=child.getMeasuredWidth();
      final int height=child.getMeasuredHeight();
      int childLeft=parentLeft;
      int childTop=parentTop;
      final int gravity=lp.gravity;
      if (gravity != -1) {
        final int horizontalGravity=gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        final int verticalGravity=gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (horizontalGravity) {
case Gravity.LEFT:
          childLeft=parentLeft + lp.leftMargin;
        break;
case Gravity.CENTER_HORIZONTAL:
      childLeft=parentLeft + (parentRight - parentLeft + lp.leftMargin + lp.rightMargin - width) / 2;
    break;
case Gravity.RIGHT:
  childLeft=parentRight - width - lp.rightMargin;
break;
default :
childLeft=parentLeft + lp.leftMargin;
}
switch (verticalGravity) {
case Gravity.TOP:
childTop=parentTop + lp.topMargin;
break;
case Gravity.CENTER_VERTICAL:
childTop=parentTop + (parentBottom - parentTop + lp.topMargin + lp.bottomMargin - height) / 2;
break;
case Gravity.BOTTOM:
childTop=parentBottom - height - lp.bottomMargin;
break;
default :
childTop=parentTop + lp.topMargin;
}
}
child.layout(childLeft,childTop,childLeft + width,childTop + height);
}
}
}