我正在尝试在我的 Android 应用程序中使用 TabHost 和 TabWidget。这是我的布局 main.xml:
<TabHost
android:id="@+id/mainTabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="65px"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/contentTags"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/contentPreferences"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
</FrameLayout>
</TabHost>
还有我的代码:
final TabHost mainTabHost = (TabHost) this.findViewById(R.id.mainTabHost);
mainTabHost.setup();
final TabHost.TabSpec tabSpecTags = mainTabHost.newTabSpec("tabTags");
tabSpecTags.setIndicator(this.getString(R.string.tab_name_tags));
tabSpecTags.setContent(R.id.contentTags);
mainTabHost.addTab(tabSpecTags);
final TabHost.TabSpec tabSpecPreferences = mainTabHost.newTabSpec("tabPreferences");
tabSpecPreferences.setIndicator(this.getString(R.string.tab_name_preferences));
tabSpecPreferences.setContent(R.id.contentPreferences);
mainTabHost.addTab(tabSpecPreferences);
问题是我不希望我的选项卡太高 (65px)。但是,如果我将 TabWidget 的 layout_height 设置为例如30px,我根本看不到标签上的标签标签(指示器)。
似乎 TabWidget 有一个“最低要求”的高度(65px?)并且指示器位于这个 65px 的底部?
有没有办法调整指标的位置?
谢谢!
最佳答案
However, if i set the layout_height of the TabWidget to e.g. 30px, i can't see the tab labels (indicator) on the tabs at all.
请注意,如果它们改变了 TabHost
的构造方式,那么在未来的 Android 版本中,执行此操作的技术不一定可靠。
Is there a way to adjust the positioning of the indicator?
从 API 级别 4(又名 Android 1.6)开始,TabHost.TabSpec
通过 setIndicator()
接受一个 View
作为指示符.我没有尝试过,但它可以让您更好地控制单个选项卡指示器的布局。
关于android - TabWidget - 如何设置指示器文本的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2170200/