2011-12-28 66 views
4

我想重複我的應用程序中的每個活動我的標籤頁腳。Android Tab喜歡頁腳

我使用這個代碼

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

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" > 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_above="@android:id/tabs" /> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" /> 

     </RelativeLayout> 

    </TabHost> 

,我要添加組件,如ListView控件,按鈕等我的標籤爲每個佈局的頂部。我怎樣才能管理這個?

+0

使用[ActivityGroup](http://stackoverflow.com/q/4601475/593709),雖然現在已經摺舊了。 – 2011-12-30 16:54:13

回答

2

我已經做了類似的擴展一個通用的基本活動,其中我重寫了方法setContentView。

abstract public class BaseActivity extends Activity { 
    @Override 
    public void setContentView(View view) { 

     // get master 
     LayoutInflater inflater = LayoutInflater.from(this); 

     // this is the master view with a container and the footer, you can 
     // as well add the header 
     RelativeLayout rlMasterView = (RelativeLayout) inflater.inflate(R.layout.master, null); 

     rlMasterView.addView(view); 

     super.setContentView(rlMasterView); 
    } 
} 

setContentView創建頁腳並將其附加到我在每個活動中設置的視圖。

我也可以在每個佈局中使用include標籤。

<include src="footer" /> 
+0

你能分享一下嗎? – BCK 2011-12-28 13:08:26

+2

我希望這可以幫助你... – sebataz 2011-12-28 13:16:06

+0

如果我想在每個佈局中使用TabHost,我該如何管理它?例如,我的佈局包含ListView,Button和底部的選項卡。 – BCK 2011-12-29 15:40:43