TabHost是选项卡的容器,是一种特殊的FrameLayout布局(帧布局)。
xml布局如下:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost">
<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="0dip"
android:layout_weight="1">
</FrameLayout>
<!-- 选项卡 -->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
</TabWidget>
</LinearLayout>
</TabHost>
如上代码所示,tabhost中必须包含framelayout,tabwidget,tabhost控件的id必须为tabhost, framelayout控件的id必须为tabcontent,tabwidget控件的id必须为tabs,这些是不能更改的。