當布局文件是這樣的時候:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.smtsokt.activity.MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="11" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
</TabWidget>
</LinearLayout>
</TabHost>
顯示為:
TabWidget的寬度改為 wrap_content 時:
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
</TabWidget>
顯示為:
我怎樣才能讓這幾個選項卡平鋪在下方呢?
終於找到大神相助
private void setWeight(TabWidget tabWidget)
{
WindowManager windowManager = getWindowManager();
Display windowDisplay = windowManager.getDefaultDisplay();
int windowWidth = windowDisplay.getWidth();
int tabWidth = windowWidth / 4; // 寬度比為:3:4:4:6:9
tabWidget.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(tabWidth, LayoutParams.FILL_PARENT));
tabWidget.getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams(tabWidth, LayoutParams.FILL_PARENT));
tabWidget.getChildAt(2).setLayoutParams(new LinearLayout.LayoutParams(tabWidth, LayoutParams.FILL_PARENT));
tabWidget.getChildAt(3).setLayoutParams(new LinearLayout.LayoutParams(tabWidth, LayoutParams.FILL_PARENT));
}