2010-06-23 56 views
0

我可以將Tab Layout嵌入其他佈局嗎?我可以將Tab Layout嵌入其他佈局嗎?

的設計佈局如下圖所示:

Root LinearLayout (vertical oritentation) 
    A ViewLayout 
    A TextLayout 
    A Tab layout 
    A View Layout 
    A TextLayout 

我只是想在我的佈局選項卡,但不是根本。可能嗎?

謝謝。

回答

2

是的,這是可能的。在你的xml中,只需將tabhost放在任何你想要的地方。你對xml有困難?

+0

導向http://developer.android.com/resources/tutorials/views/hello-tabwidget.html說:「TabHost必須佈局的根節點「 這使我困惑。 TabHost必須成爲XML的根源嗎? – user256239 2010-06-23 20:47:01

+0

你說得對。我可以在XML中添加TabWidget上方的任何其他佈局,以將該佈局放在製表符佈局的上方。 – user256239 2010-06-24 01:34:24

+0

我不知道他們爲什麼說在教程中,也許這只是爲了他們的教程示例。你可以把它放在任何你喜歡的地方。此外,您的活動可以但不一定需要從TabActivity擴展。我在常規活動中也以這種方式使用標籤,而不是根元素。 – 2010-06-24 04:14:27

4

你的問題是,tabHost不是根。看到這個代碼 - 它把標籤上方的元素...

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@android:id/tabhost" 
    style="@style/page" > 

    <RelativeLayout style="@style/page" > 

     <RelativeLayout 
      android:id="@+id/rell" 
      android:layout_width="360dp" 
      android:layout_height="66dp" > 

      <ImageView 
       android:layout_width="211dp" 
       android:layout_height="64dp" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:src="@drawable/semple_img" /> 
     </RelativeLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="61dp" 
      android:layout_below="@id/rell"> 
       </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@android:id/tabs" > 
     </FrameLayout> 
    </RelativeLayout> 

</TabHost> 
相關問題