2011-03-30 37 views
1

您好我如何設置選項卡在同一屏幕的底部和頂部。我需要顯示在屏幕頂部的一個選項卡和另一個在同一屏幕的底部。任何機構知道如何做到提前感謝在Android中的標籤

+0

這是什麼樣的設計?在底部和頂部選項卡? – 2011-03-30 06:04:21

+0

我認爲它不是很好的設計實踐。 Neways你可以使用頂部+底部的按鈕,而不是製表符來實現這一點。 – 2011-03-30 06:22:33

+0

你不能設置你需要指定一個位置頂部或底部的標籤 – Sumant 2011-03-30 06:36:28

回答

0
您可以使用鏈接來設置在底部 custom tabs 一個標籤,也看看這個示例代碼

喜拉克什

public class Tab App extends Tab Activity { 

@覆蓋 保護無效的onCreate(捆綁savedInstanceState){ super.onCreate(savedInstanceState);

Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 
    tabHost.removeAllViews(); 
    TabWidget tabs = new TabWidget(this); 
    tabs.setId(android.R.id.tabs); 
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); 
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
    tabs.setLayoutParams(params); 
    FrameLayout content = new FrameLayout(this); 
    content.setId(android.R.id.tabcontent); 
    content.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    RelativeLayout relative = new RelativeLayout(this); 
    relative.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    relative.addView(content); 
    relative.addView(tabs); 
    tabHost.addView(relative); 
    tabHost.setup(); 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, AndroidBrowser.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("tag1") 
     .setIndicator("tag1",res.getDrawable(R.drawable.cw)) 
           .setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, CWBrowser.class); 
    spec = tabHost.newTabSpec("tag2") 
     .setIndicator("tag2",res.getDrawable(R.drawable.cw)) 
           .setContent(intent); 
    tabHost.addTab(spec); 

    intent = new Intent().setClass(this, CWBrowser.class); 
    spec = tabHost.newTabSpec("tag3") 
     .setIndicator("tag3",res.getDrawable(R.drawable.cw)) 
           .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
}` 
+0

您好araf感謝您的幫助,但此代碼將顯示在底部的標籤只,我想同時顯示頂部和底部選項卡,都在相同屏幕 – 2011-03-30 06:37:26