Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc3f7937 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android (Google) Code Review
Browse files

Merge "Tabs are resized to make sure they fit in their parent." into honeycomb

parents 55271a79 6741c941
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -140,6 +140,55 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
        setOnFocusChangeListener(this);
    }

    /**
     * {@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.
     *
@@ -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();
+1 −1
Original line number Diff line number Diff line
@@ -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
+24 −10
Original line number Diff line number Diff line
@@ -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>
</TabHost>