2

我已经研究了很多如何使用此代码对齐页面底部的选项卡,但我没有找到任何内容,我将代码用作:

public class MainActivity  extends TabActivity {

    /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    TabHost tabHost = getTabHost();   

    tabHost.addTab(tabHost.newTabSpec("tab1")
            .setIndicator("Home")
            .setContent(new Intent(this, TabGroup1Activity.class)));

    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("Search"/*, getResources().getDrawable(R.drawable.ic_launcher)*/)
            .setContent(new Intent(this, TabGroup2Activity.class))
            );

    tabHost.addTab(tabHost.newTabSpec("tab3")
            .setIndicator("About Us")
            .setContent(new Intent(this, TabGroup3Activity.class)));

     tabHost.getTabWidget().setCurrentTab(0);
    tabHost.getTabWidget().setGravity(Gravity.BOTTOM);

TabGroup1Activity 是:

public class TabGroup1Activity extends TabGroupActivity{
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startChildActivity("HomeActivity", new Intent(this,HomeActivity.class));
    }
}

通过使用此代码,标签栏出现在屏幕顶部,但我想将其放在底部..请提出一些建议,我发现这种方法很容易创建标签

4

1 回答 1

0
   public void addNewTab(Context context, String title, int height){
  TabHost tabHost = getTabHost();  // The activity TabHost
  Intent intent = new Intent().setClass(context, HelloTabsActivity.class);
  TabHost.TabSpec spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title).setContent(intent);
 tabHost.addTab(spec);

int totalTabs = tabHost.getTabWidget().getChildCount();
 ((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).removeViewAt(0);
 ((TextView)((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).getChildAt(0)).setHeight(30);
 tabHost.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = height;
  }
于 2012-08-06T11:19:08.173 回答