开发者

TabWidget Height

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


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.


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.


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... ^^


Tab hight is frame work dependent.you should customize it from there only or customize some other view to look like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜