Android 1.6 TabHost inside a Fragment

别来无恙 提交于 2019-11-28 12:48:08

In generally accepted practices, Tabs fit the whole screen. Most people (including me) are unaware the tabs can be placed anywhere like a simple view, ListView. The trick is to include your TabHost inside another layout. When you create the TabHost, always keep these id : tabhost , tabs , tabcontent

In your main layout, include your tabhost.xml . Here I center the TabHost in the middle

<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>

Look well at the Tabs and TabsPager examples in Support4Demos , the TabHost is still managed by FragmentActivity. Each tab content is a fragment. With TabActivity, it may not be possible to have a tab anywhere

At the end, this is what it looks like

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!