2013-02-27 110 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>