diff options
-rw-r--r-- | core/java/android/widget/FrameLayout.java | 71 |
1 files changed, 37 insertions, 34 deletions
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java index 940fec1..26e191d 100644 --- a/core/java/android/widget/FrameLayout.java +++ b/core/java/android/widget/FrameLayout.java @@ -76,6 +76,8 @@ public class FrameLayout extends ViewGroup { boolean mForegroundBoundsChanged = false; + private static final int DEFAULT_CHILD_GRAVITY = Gravity.TOP | Gravity.LEFT; + public FrameLayout(Context context) { super(context); } @@ -307,41 +309,42 @@ public class FrameLayout extends ViewGroup { 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 - width) / 2 + - lp.leftMargin - lp.rightMargin; - break; - case Gravity.RIGHT: - childLeft = parentRight - width - lp.rightMargin; - break; - default: - childLeft = parentLeft + lp.leftMargin; - } + int gravity = lp.gravity; + if (gravity == -1) { + gravity = DEFAULT_CHILD_GRAVITY; + } - switch (verticalGravity) { - case Gravity.TOP: - childTop = parentTop + lp.topMargin; - break; - case Gravity.CENTER_VERTICAL: - childTop = parentTop + (parentBottom - parentTop - height) / 2 + - lp.topMargin - lp.bottomMargin; - break; - case Gravity.BOTTOM: - childTop = parentBottom - height - lp.bottomMargin; - break; - default: - childTop = parentTop + lp.topMargin; - } + 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 - width) / 2 + + lp.leftMargin - lp.rightMargin; + 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 - height) / 2 + + lp.topMargin - lp.bottomMargin; + break; + case Gravity.BOTTOM: + childTop = parentBottom - height - lp.bottomMargin; + break; + default: + childTop = parentTop + lp.topMargin; } child.layout(childLeft, childTop, childLeft + width, childTop + height); |