diff options
| author | 2011-03-09 00:15:38 -0800 | |
|---|---|---|
| committer | 2011-03-09 00:17:42 -0800 | |
| commit | 2b0952b197470a457f4f436911f1d07f553d15da (patch) | |
| tree | 06d2f577d946841f27b4ba27d94524a3e2dc1051 | |
| parent | 949d0c8c384437d92fc1432b750da6da59df1fa7 (diff) | |
Fix bug 4065021 - Adjust spacing of the "home" action bar item to be
consistent with the "up" indicator
Make sure that the "home" affordance in the action bar always occupies
the same amount of space regardless of whether or not the "up"
indicator is visible. This means centering the application icon/logo
in the remaining space after the "up" indicator has been added.
Change-Id: I3c81cfe8255546d4dd676af913895713baba4f13
| -rw-r--r-- | core/java/com/android/internal/widget/ActionBarView.java | 57 | ||||
| -rw-r--r-- | core/res/res/layout/action_bar_home.xml | 14 |
2 files changed, 64 insertions, 7 deletions
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java index a41b348af629..586ba87707bf 100644 --- a/core/java/com/android/internal/widget/ActionBarView.java +++ b/core/java/com/android/internal/widget/ActionBarView.java @@ -43,6 +43,7 @@ import android.view.ViewGroup; import android.view.ViewParent; import android.view.Window; import android.widget.AdapterView; +import android.widget.FrameLayout; import android.widget.HorizontalScrollView; import android.widget.ImageView; import android.widget.LinearLayout; @@ -957,4 +958,60 @@ public class ActionBarView extends ViewGroup { } } } + + private static class HomeView extends FrameLayout { + private View mUpView; + private View mIconView; + + public HomeView(Context context) { + this(context, null); + } + + public HomeView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onFinishInflate() { + mUpView = findViewById(com.android.internal.R.id.up); + mIconView = (ImageView) findViewById(com.android.internal.R.id.home); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + measureChildWithMargins(mUpView, widthMeasureSpec, 0, heightMeasureSpec, 0); + final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams(); + int width = upLp.leftMargin + mUpView.getMeasuredWidth() + upLp.rightMargin; + int height = upLp.topMargin + mUpView.getMeasuredHeight() + upLp.bottomMargin; + measureChildWithMargins(mIconView, widthMeasureSpec, width, heightMeasureSpec, 0); + final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); + width += iconLp.leftMargin + mIconView.getMeasuredWidth() + iconLp.rightMargin; + height = Math.max(height, + iconLp.topMargin + mIconView.getMeasuredHeight() + iconLp.bottomMargin); + setMeasuredDimension(width, height); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + final int vCenter = (b - t) / 2; + int width = r - l; + if (mUpView.getVisibility() != GONE) { + final LayoutParams upLp = (LayoutParams) mUpView.getLayoutParams(); + final int upHeight = mUpView.getMeasuredHeight(); + final int upWidth = mUpView.getMeasuredWidth(); + final int upTop = t + vCenter - upHeight / 2; + mUpView.layout(l, upTop, l + upWidth, upTop + upHeight); + final int upOffset = upLp.leftMargin + upWidth + upLp.rightMargin; + width -= upOffset; + l += upOffset; + } + final LayoutParams iconLp = (LayoutParams) mIconView.getLayoutParams(); + final int iconHeight = mIconView.getMeasuredHeight(); + final int iconWidth = mIconView.getMeasuredWidth(); + final int hCenter = (r - l) / 2; + final int iconLeft = l + iconLp.leftMargin + hCenter - iconWidth / 2; + final int iconTop = t + iconLp.topMargin + vCenter - iconHeight / 2; + mIconView.layout(iconLeft, iconTop, iconLeft + iconWidth, iconTop + iconHeight); + } + } } diff --git a/core/res/res/layout/action_bar_home.xml b/core/res/res/layout/action_bar_home.xml index 7867577a9442..c82f91d7dfd8 100644 --- a/core/res/res/layout/action_bar_home.xml +++ b/core/res/res/layout/action_bar_home.xml @@ -14,14 +14,14 @@ limitations under the License. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:background="?android:attr/selectableItemBackground" - android:orientation="horizontal"> +<view xmlns:android="http://schemas.android.com/apk/res/android" + class="com.android.internal.widget.ActionBarView$HomeView" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:background="?android:attr/selectableItemBackground" > <ImageView android:id="@android:id/up" android:src="?android:attr/homeAsUpIndicator" - android:layout_gravity="top|left" + android:layout_gravity="center_vertical|left" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -33,4 +33,4 @@ android:paddingRight="16dip" android:layout_gravity="center" android:scaleType="center" /> -</LinearLayout> +</view> |