summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/widget/TabWidget.java50
-rw-r--r--core/java/android/widget/TableLayout.java2
-rw-r--r--core/res/res/layout/tab_content.xml34
3 files changed, 75 insertions, 11 deletions
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index ce4e8e5..51ece33 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 7f26e28..842b087 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
diff --git a/core/res/res/layout/tab_content.xml b/core/res/res/layout/tab_content.xml
index 79147fb..3fa4494 100644
--- a/core/res/res/layout/tab_content.xml
+++ b/core/res/res/layout/tab_content.xml
@@ -18,16 +18,30 @@
*/
-->
-<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"
- android:layout_width="match_parent" android:layout_height="match_parent">
- <LinearLayout android:orientation="vertical"
- android:layout_width="match_parent" android:layout_height="match_parent">
- <TabWidget android:id="@android:id/tabs"
- android:orientation="horizontal" android:layout_width="match_parent"
- android:layout_height="wrap_content" android:layout_weight="0" />
- <FrameLayout android:id="@android:id/tabcontent"
- android:layout_width="match_parent" android:layout_height="0dip"
+<TabHost
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/tabhost"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TabWidget
+ android:id="@android:id/tabs"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="0"/>
+
+ <FrameLayout
+ android:id="@android:id/tabcontent"
+ android:layout_width="match_parent"
+ android:layout_height="0dip"
android:layout_weight="1"/>
- </LinearLayout>
+
+ </LinearLayout>
</TabHost>