0

我是 android 新手,我想显示一个 TabWidget,其Tabspec 应该具有相同的大小......它们里面有什么并不重要......此外,我添加了一个 Horizo​​ntallScrollView 因为我想在其中显示 8 个选项卡我的活动,不仅3...

有人知道我必须在我的 xml 中添加什么才能让我的 8 个活动具有相同的选项卡大小吗?

<?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"
        android:padding="5dp">
        <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:scrollbarAlwaysDrawHorizontalTrack="true"
                android:scrollbars="horizontal"/>
        </HorizontalScrollView>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>

</TabHost>

谢谢

4

1 回答 1

0

通常会创建一个这样的选项卡:

tabHost.addTab(tabHost.newTabSpec("tag")
                .setIndicator("tab title", icon))
                .setContent(this));

这导致TabHost创建它选择托管TabSpec的视图。但是setIndicator有一个重载,它将View作为参数。因此,您可以创建一个固定宽度的视图,并为您的TabSpecs使用setIndicator的这种重载。

于 2011-03-22T23:54:56.210 回答