2014-04-18 32 views
1

我是Android的noob。我已經設置了FragmentTabHost現在我有一個問題,有ViewGroup FragmeLayout,它名爲「tabcontent」。這裏有什麼用途?Android中的FragmentTabHost中的TabContent

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:layout_weight="0" /> 

    <FrameLayout 
     android:id="@+id/realtabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 

    <TabWidget 
     android:id="@android:id/tabs" 

     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="horizontal" /> 
</LinearLayout> 

回答

0

在TabContet中,可以定義每個標籤的根元素。 在tabcontent中有兩個使用Scrollview和Relative佈局的示例。 我建議你使用Tabhost作爲你的tabwidget的父項。

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent"> 

     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

      <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

       <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" > 

        <ScrollView 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="fill_parent"> 
        </ScrollView> 

        <RelativeLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" > 
        </RelativeLayout> 

      </FrameLayout> 
     </LinearLayout> 
</TabHost> 

之後,編程初始化選項卡中的活動lkie這

TabHost tabs=(TabHost)findViewById(android.R.id.tabhost); 
tabs.setup(); 


    TabHost.TabSpec spec=tabs.newTabSpec("Tittle"); 
    spec.setContent(R.id.tab1); 
    spec.setIndicator("Tab 1"); 
    tabs.addTab(spec); 

    spec=tabs.newTabSpec("Tittle"); 
    spec.setContent(R.id.tab2); 
    spec.setIndicator("Tab 2"); 
    tabs.addTab(spec); 

    tabs.setCurrentTab(0); 

希望它可以幫助你。

+0

這是你所說的不同的事情。您現在使用的方式已被棄用 – Mick