【问题标题】:(Android) How to change the size of the tabs in a tabWidget ?(Android) 如何更改 tabWidget 中标签的大小?
【发布时间】:2014-06-16 09:44:21
【问题描述】:

我需要更改 tabWidget 中 2 个选项卡的大小,但我试过了:

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

但是没用。

这是我得到的:

    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
    TabSpec secondTabSpec = tabHost.newTabSpec("tid1");


    firstTabSpec.setIndicator("Calendrier").setContent(new Intent(this,PremiereTab.class));
    secondTabSpec.setIndicator("Convoiturage").setContent(new Intent(this,DeuxiemeTab.class));

    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);

还有我的 XML 文件:

<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:id="@+id/LinearLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TabWidget>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </FrameLayout>

</LinearLayout>   
</TabHost>

我找了半天没有成功,请大家帮忙!

【问题讨论】:

    标签: android xml eclipse android-tabhost tabwidget


    【解决方案1】:

    你可以改变你的 xml :

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TabWidget>
    

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="30dp" >
    </TabWidget>
    

    希望对你有帮助..

    【讨论】:

      猜你喜欢
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多