在普遍接受的实践中,选项卡适合整个屏幕。大多数人(包括我)都不知道选项卡可以像简单的视图 ListView 一样放置在任何地方。诀窍是将您的 TabHost 包含在另一个布局中。创建 TabHost 时,请始终保留这些 id:tabhost、tabs、tabcontent
在您的主布局中,包括您的 tabhost.xml 。在这里,我将 TabHost 居中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Fill whatever you need -->
<FrameLayout
android:id="@+id/widget_fragment"
android:layout_centerVertical="true" android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<include layout="@layout/tabhost" />
</FrameLayout>
</LinearLayout>
好好看看 Support4Demos 中的 Tabs 和 TabsPager 示例,TabHost 仍然由 FragmentActivity 管理。每个选项卡内容都是一个片段。使用 TabActivity,可能无法在任何地方都有选项卡
最后,这就是它的样子
