diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 17:39:46 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-18 17:39:46 -0700 |
commit | 105925376f8d0f6b318c9938c7b83ef7fef094da (patch) | |
tree | 3b19ee2bd8704cb9c6a0da7e42dec6759183de6d /core/java/android/widget/FrameLayout.java | |
parent | ba87e3e6c985e7175152993b5efcc7dd2f0e1c93 (diff) | |
download | frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.zip frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.tar.gz frameworks_base-105925376f8d0f6b318c9938c7b83ef7fef094da.tar.bz2 |
auto import from //branches/cupcake_rel/...@140373
Diffstat (limited to 'core/java/android/widget/FrameLayout.java')
-rw-r--r-- | core/java/android/widget/FrameLayout.java | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java index 8aafee2..2bb716c 100644 --- a/core/java/android/widget/FrameLayout.java +++ b/core/java/android/widget/FrameLayout.java @@ -56,6 +56,7 @@ public class FrameLayout extends ViewGroup { private final Rect mSelfBounds = new Rect(); private final Rect mOverlayBounds = new Rect(); private int mForegroundGravity = Gravity.FILL; + private boolean mForegroundInPadding = true; public FrameLayout(Context context) { super(context); @@ -71,6 +72,9 @@ public class FrameLayout extends ViewGroup { TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.FrameLayout, defStyle, 0); + mForegroundGravity = a.getInt( + com.android.internal.R.styleable.FrameLayout_foregroundGravity, mForegroundGravity); + final Drawable d = a.getDrawable(com.android.internal.R.styleable.FrameLayout_foreground); if (d != null) { setForeground(d); @@ -80,8 +84,8 @@ public class FrameLayout extends ViewGroup { setMeasureAllChildren(true); } - mForegroundGravity = a.getInt(com.android.internal.R.styleable.FrameLayout_foregroundGravity, - mForegroundGravity); + mForegroundInPadding = a.getBoolean( + com.android.internal.R.styleable.FrameLayout_foregroundInsidePadding, true); a.recycle(); } @@ -105,6 +109,23 @@ public class FrameLayout extends ViewGroup { } mForegroundGravity = foregroundGravity; + + + if (mForegroundGravity == Gravity.FILL && mForeground != null) { + Rect padding = new Rect(); + if (mForeground.getPadding(padding)) { + mForegroundPaddingLeft = padding.left; + mForegroundPaddingTop = padding.top; + mForegroundPaddingRight = padding.right; + mForegroundPaddingBottom = padding.bottom; + } + } else { + mForegroundPaddingLeft = 0; + mForegroundPaddingTop = 0; + mForegroundPaddingRight = 0; + mForegroundPaddingBottom = 0; + } + requestLayout(); } } @@ -167,12 +188,14 @@ public class FrameLayout extends ViewGroup { if (drawable.isStateful()) { drawable.setState(getDrawableState()); } - Rect padding = new Rect(); - if (drawable.getPadding(padding)) { - mForegroundPaddingLeft = padding.left; - mForegroundPaddingTop = padding.top; - mForegroundPaddingRight = padding.right; - mForegroundPaddingBottom = padding.bottom; + if (mForegroundGravity == Gravity.FILL) { + Rect padding = new Rect(); + if (drawable.getPadding(padding)) { + mForegroundPaddingLeft = padding.left; + mForegroundPaddingTop = padding.top; + mForegroundPaddingRight = padding.right; + mForegroundPaddingBottom = padding.bottom; + } } } else { setWillNotDraw(true); @@ -309,10 +332,14 @@ public class FrameLayout extends ViewGroup { final Rect selfBounds = mSelfBounds; final Rect overlayBounds = mOverlayBounds; - selfBounds.set(0, 0, w, h); + if (mForegroundInPadding) { + selfBounds.set(0, 0, w, h); + } else { + selfBounds.set(mPaddingLeft, mPaddingTop, w - mPaddingRight, h - mPaddingBottom); + } + Gravity.apply(mForegroundGravity, foreground.getIntrinsicWidth(), foreground.getIntrinsicHeight(), selfBounds, overlayBounds); - foreground.setBounds(overlayBounds); } } |