2013-02-27 108 views
0

我有一個TabHost佈局(下面的代碼)使用TabHost包括其他佈局

<TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myTabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="65dp" > 
    </TabWidget> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingTop="65dp" > 

     <LinearLayout 
      android:id="@+id/content" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </FrameLayout> 
</TabHost> 

我加載了TabHost和有關活動的每一個裏面的東西有些活動確定。但我的問題是關於加載另一個佈局在TabHost頂部通過包含標記, 像LinearLayout其他佈局,我把一個包含標記,它是好的,但在TabHost我不能這樣做,因爲添加後包括TabHost UI被破壞
。 請告訴我如何解決這個問題

回答

2

與另一LinearLayout標籤包裝你TabHost標籤像這樣:

<LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 
      <!-- inclde goes here --> 
      <TabHost 
       android:id="@+id/myTabHost" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 
         <!-- Other tags as you have already. --> 
      </TabHost> 
</LinearLayout> 
1

然後將LinearLayout作爲父母TabHost和包括LinearLayout使用包括如下其它layouts標籤:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/myLinearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    <TabHost 
     android:id="@+id/myTabHost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="65dp" > 
    </TabWidget> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingTop="65dp" > 

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
    </LinearLayout> 
    </FrameLayout> 
    </TabHost> 
</LinearLayout>