首页 文章

在Android上居中选项卡名称

提问于
浏览
0

我已经按照官方的HelloTabWidget Android教程进行操作,它完美无缺 . 接下来,我删除了标签图标,它仍然完美无缺 . 现在我想在每个标签中水平和垂直地将tabtext集中在一起,但是我无能为力 . 我试过搜索但找不到解决方案 .

我已经尝试将android:layout_gravity添加到我的main.xml文件中,但它没有帮助 .

这是我的onCreate main.java文件:

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  TabHost tabHost = getTabHost();  // The activity TabHost
  TabHost.TabSpec spec;  // Resusable TabSpec for each tab
  Intent intent;  // Reusable Intent for each tab

  intent = new Intent().setClass(this, Indkobsliste.class);
  spec = tabHost.newTabSpec("tab1").setIndicator("Tab1")
                .setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, Opskrifter.class);
  spec = tabHost.newTabSpec("tab2").setIndicator("Tab2")
                .setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, Madplan.class);
  spec = tabHost.newTabSpec("tab3").setIndicator("Tab3")
                      .setContent(intent);
  tabHost.addTab(spec);

  tabHost.setCurrentTab(1);
}

这是main.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp">
        <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="match_parent"
            android:padding="5dp"/>
    </LinearLayout>
</TabHost>

这就是我的标签现在的样子:
My tabs

1 回答

相关问题