2

I used to use :

tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =50;

to set my tab height.

But I would like to move this tab height setting from Java code to layout xml files with the purpose to use different height value for layout/main.xml and layout-large/main.xml

My question is how to set tab height in xml file?

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">


        </FrameLayout>
      </LinearLayout>
</TabHost>
David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
Mellon
  • 37,586
  • 78
  • 186
  • 264

2 Answers2

2

you can specify the height of tab in dip what ever you need. You can either use the Property window or directly given in .Xml file.

          <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="50dip" />
Asish AP
  • 4,421
  • 2
  • 28
  • 50
0

In additional to set height in xml

<TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="@dimen/tab_height" />

I also made some actions in code

int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, res.getDimension(R.dimen.tab_height), res.getDisplayMetrics());
    for (int i=0; i<mTabHost.getTabWidget().getTabCount(); i++)
    {
        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = height;
    }

This make tab height and position of blue strip line correct. Without java code blue line may appears over stretched tabs.

Sergii.PSP
  • 71
  • 4