3

內部在演示Support4Demos - API 4+ Support Demos,凸片和TabsPager例子都延伸FragmentActivity。每個標籤內容本身就是一個片段。沒有真正的突破,TabActivity在沒有引入片段的情況下也以相同的方式使用。的Android 1.6 TabHost片段

現在假設在我的Activity中,屏幕部分是一個名爲WidgetFragment的片段。 WidgetFragment如何包含TabHost?可視化包含在Activity中的迷你TabHost。 我嘗試了所有可能的方式在片段中插入一個TabHost而不是FragmentActivity。

+0

而當你試圖「無微不至」,發生了什麼? – CommonsWare

+0

沒有工作,這就是爲什麼我問:)。試圖在Fragment內部實現它,就像在演示中的FragmentActivity內完成它一樣。 –

+0

請定義「沒有工作」。 – CommonsWare

回答

5

在普遍接受的慣例,標籤適應整個屏幕。 大多數人(包括我)都不知道標籤可以放在任何地方,就像一個簡單的視圖ListView。 訣竅是將您的TabHost包含在另一個佈局中。當您創建TabHost,始終保持這些ID:tabhost,標籤,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的標籤和TabsPager例子看看好了,TabHost仍然由FragmentActivity管理。每個標籤內容都是一個片段。隨着TabActivity,也未必能在任何地方

在最後一個標籤,這是什麼樣子

enter image description here