diff options
| author | Gilles Debunne <debunne@google.com> | 2011-01-26 18:09:23 -0800 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-26 18:09:23 -0800 |
| commit | bc3f79371bb93e075bcb91d92180487337afce17 (patch) | |
| tree | 74ba45db6869a36ac403d0fa2564f583d64774ba /core/java/android | |
| parent | 55271a79d1c14e2952d550995569135a23971672 (diff) | |
| parent | 6741c941a76d17c257c396d86c7561aa43005b1a (diff) | |
Merge "Tabs are resized to make sure they fit in their parent." into honeycomb
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/widget/TabWidget.java | 50 | ||||
| -rw-r--r-- | core/java/android/widget/TableLayout.java | 2 |
2 files changed, 51 insertions, 1 deletions
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java index ce4e8e5230d0..51ece3318616 100644 --- a/core/java/android/widget/TabWidget.java +++ b/core/java/android/widget/TabWidget.java @@ -141,6 +141,55 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { } /** + * {@inheritDoc} + */ + @Override + void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) { + // First measure with no constraint + final int unspecifiedWidth = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + super.measureHorizontal(unspecifiedWidth, heightMeasureSpec); + + final int count = getChildCount(); + int totalWidth = 0; + int totalCount = 0; + for (int i = 0; i < count; i++) { + final View child = getChildAt(i); + if (child.getVisibility() == GONE) { + continue; + } + final int childWidth = child.getMeasuredWidth(); + totalWidth += childWidth; + totalCount++; + } + + final int width = MeasureSpec.getSize(widthMeasureSpec); + if (totalWidth > width && totalCount > 0) { + int extraWidth = totalWidth - width; + for (int i = 0; i < count; i++) { + final View child = getChildAt(i); + if (child.getVisibility() == GONE) { + continue; + } + final int childWidth = child.getMeasuredWidth(); + final int delta = extraWidth / totalCount; + final int tabWidth = Math.max(0, childWidth - delta); + + final int tabWidthMeasureSpec = MeasureSpec.makeMeasureSpec( + tabWidth, MeasureSpec.EXACTLY); + final int tabHeightMeasureSpec = MeasureSpec.makeMeasureSpec( + child.getMeasuredHeight(), MeasureSpec.EXACTLY); + + child.measure(tabWidthMeasureSpec, tabHeightMeasureSpec); + + // Make sure the extra width is evenly distributed, avoiding int division remainder + extraWidth -= delta; + totalCount--; + } + setMeasuredDimension(width, getMeasuredHeight()); + } + } + + /** * Returns the tab indicator view at the given index. * * @param index the zero-based index of the tab indicator view to return @@ -175,6 +224,7 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener { * Sets the drawable to use as a divider between the tab indicators. * @param drawable the divider drawable */ + @Override public void setDividerDrawable(Drawable drawable) { mDividerDrawable = drawable; requestLayout(); diff --git a/core/java/android/widget/TableLayout.java b/core/java/android/widget/TableLayout.java index 7f26e28b0770..842b0870eeb2 100644 --- a/core/java/android/widget/TableLayout.java +++ b/core/java/android/widget/TableLayout.java @@ -560,7 +560,7 @@ public class TableLayout extends LinearLayout { if ((totalWidth > size) && (mShrinkAllColumns || mShrinkableColumns.size() > 0)) { // oops, the largest columns are wider than the row itself - // fairly redistribute the row's widh among the columns + // fairly redistribute the row's width among the columns mutateColumnsWidth(mShrinkableColumns, mShrinkAllColumns, size, totalWidth); } else if ((totalWidth < size) && (mStretchAllColumns || mStretchableColumns.size() > 0)) { // if we have some space left, we distribute it among the |
