Android 1.6 TabHost inside a Fragment

前端 未结 1 1049
轮回少年
轮回少年 2020-12-11 09:20

In the demo Support4Demos - API 4+ Support Demos , the Tabs and TabsPager examples both extend FragmentActivity. Each tab content is itself a Fragment. No real breakthrough,

相关标签:
1条回答
  • 2020-12-11 09:40

    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

    enter image description here

    0 讨论(0)
提交回复
热议问题