【发布时间】:2012-03-15 04:49:53
【问题描述】:
我遵循了官方的 HelloTabWidget Android 教程,它运行良好。接下来我删除了选项卡图标,它仍然可以正常工作。现在我想在每个选项卡中将 tabtext 水平和垂直居中,但我不知道如何。我试过搜索,但找不到解决方案。
我尝试将 android:layout_gravity 添加到我的 main.xml 文件中,但没有帮助。
这是我的 onCreate main.java 文件:
公共无效 onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 设置内容视图(R.layout.main); TabHost tabHost = getTabHost(); // 活动 TabHost TabHost.TabSpec 规范; // 每个选项卡的可重用 TabSpec 意图意图; // 每个选项卡的可重用意图 intent = new Intent().setClass(this, Indkobsliste.class); 规格 = tabHost.newTabSpec("tab1").setIndicator("Tab1") .setContent(意图); tabHost.addTab(spec); intent = new Intent().setClass(this, Opskrifter.class); 规格 = tabHost.newTabSpec("tab2").setIndicator("Tab2") .setContent(意图); tabHost.addTab(spec); intent = new Intent().setClass(this, Madplan.class); 规格 = tabHost.newTabSpec("tab3").setIndicator("Tab3") .setContent(意图); 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>
这是我的标签现在的样子:
【问题讨论】: