【问题标题】:Android: TabHost.TabSpec setIndicator (CharSequence label)Android:TabHost.TabSpec setIndicator(CharSequence 标签)
【发布时间】:2010-12-16 10:57:13
【问题描述】:

我正在尝试创建一个选项卡 UI,但我不想在 tabHosts 上放置任何图像,因此我决定使用 setIndicator(CharSequence 标签)而不是使用 setIndicator(CharSequence label,Drawable icon)。然后在没有图像的情况下创建 tabHost,但在高度较小且仅包含 CharSequence 的情况下,它与带有图像的常规 tabHost 具有相同的高度。图像通常位于的顶部有一个空闲空间,而文本位于该空间下方。无论如何要删除为图像保留的可用空间,或者翻转两者,以便文本位于顶部,之后我可以设置一个 15dp 的 layout_height 。主布局的 .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="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</LinearLayout>
</TabHost>

【问题讨论】:

    标签: android xml android-tabhost


    【解决方案1】:

    您可以将@null 设置为背景,并设置负边距以删除可用空间。

    <TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@null"
    android:layout_marginLeft="-2dp"
    android:layout_marginRight="-2dp" />
    

    【讨论】:

    • 将@null 设置为背景没有帮助,我只需要删除 TabWidget 顶部的空白区域,而不是左右,但感谢您的建议,我发现我可以设置 android:layout_marginTop="-25dp" 它解决了我的问题(我决定在顶部留出一些空间,以便用户在更改标签时不会挣扎)谢谢你的建议!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    相关资源
    最近更新 更多