Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabWidget Height

Tags:

android

Is it possible to set the TabWidget height and have the tab labels adjust?

If I set the TabWidget height too small, then the labels are hidden from view.

<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"
            android:padding="5dp">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="30px" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
    </LinearLayout>
</TabHost>

Thanks

like image 606
Steve Avatar asked Mar 23 '10 19:03

Steve


3 Answers

The following code adjusts the height on the tabs:

for (int i = 0; i < tabHost.getTabWidget().getTabCount(); i++) {
    tabHost.getTabWidget().getChildAt(i).getLayoutParams().height = 33;
}  

However, this will create a defect on the background color of the un-selected tab. I don'n know how to solve this yet. Some forums suggest it is not solvable without making a custom tab widget.

like image 161
Vanja Avatar answered Oct 14 '22 11:10

Vanja


Android 1.6 added a setIndicator() method on TabSpec that accepts a View. I have not tried it yet, but my understanding is that it will give you greater control over the tabs.

like image 9
CommonsWare Avatar answered Oct 14 '22 12:10

CommonsWare


i see... when u addTab, usually we use setIndicator like this:

QTabHost.addTab(QTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").bla bla....

u can use TextView to replace "TAB 2", became like this:

tview=new TextView(this); tview.setText("Title here"); QTabHost.addTab(QTabHost.newTabSpec("tab_test2").setIndicator(tview).bla bla....

all u need is just modify the textview. Thanks... ^^

like image 2
Rubin Happy Ch. Avatar answered Oct 14 '22 12:10

Rubin Happy Ch.