Android:BOTTOM上的标签

lla*_*all 148 android tabwidget

我已经看到一些关于这个的喋喋不休,但没有什么明确的.有没有办法将TabWidget中的标签放到屏幕底部?如果是这样,怎么样?

我尝试了以下,但没有奏效:

a)在tablayout下面设置tabwidget
b)将tabwidget的引力设置为"bottom"

谢谢!llappall

sto*_*986 272

这是最简单,最强大,可扩展的解决方案,可以在屏幕底部显示标签.

  1. 在垂直LinearLayout中,将FrameLayout放在TabWidget上方
  2. 设置layout_heightwrap_contentFrameLayout和TabWidget
  3. 设置FrameLayout的 android:layout_weight="1"
  4. 设置TabWidget android:layout_weight="0"(默认为0,但强调,可读性等)
  5. 设置TabWidget android:layout_marginBottom="-4dp"(删除底部分隔符)

完整代码:

<?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"
        android:padding="5dp">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="5dp"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:layout_marginBottom="-4dp"/>

    </LinearLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

  • 为了摆脱TabWidget底部的分隔符,只需将"android:layout_marginBottom =" - 5px"`添加到TabWidget即可.这会将TabWidget从屏幕底部移开5个像素,这样就足以让你看不到分隔线了.FrameLayout将在大小上进行补偿,因此它可以完美地运行.我不确定分配器的大小是否会在较大的设备上发生变化.您可能必须使用`dp`而不是`px`. (19认同)
  • 您应该选择此(或其他)作为接受的答案. (6认同)
  • Google标准TabWidget示例中唯一需要的偏差是在FrameLayout上设置`layout_weight = 1`.这允许选项卡控件首先从LinearLayout"声明"其高度. (4认同)
  • 分隔符实际上是硬编码的.我试图更改用于选项卡的drawable并找到它.完全无赖. (3认同)

Lea*_*dro 38

试试吧;)只是看的FrameLayout(@ ID/tabcontent)的内容,因为我不知道它将如何在滚动的情况下,处理......对我来说,它的作品,因为我使用的ListView作为我的选项卡的内容.:) 希望能帮助到你.

<?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">
    <RelativeLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
        <FrameLayout android:id="@android:id/tabcontent"
             android:layout_width="fill_parent" 
             android:layout_height="fill_parent"
             android:layout_alignParentTop="true" 
             android:layout_above="@android:id/tabs" />
    <TabWidget android:id="@android:id/tabs"
             android:layout_width="fill_parent" 
             android:layout_height="wrap_content"
             android:layout_alignParentBottom="true" />
    </RelativeLayout>
</TabHost>
Run Code Online (Sandbox Code Playgroud)

  • +1但你注意到屏幕顶部的黑/灰条了吗?你是怎么删除它的? (4认同)

Bri*_*pin 12

有一种方法可以删除该行.

1)按照本教程: android-tabs-with-fragments

2)然后应用Leaudro上面建议的RelativeLayout更改(将布局道具应用于所有FrameLayouts).

您还可以将ImageView添加到项目#1中的tab.xml,并获得类似于iPhone的标签.

这是我正在进行的工作的截图.我还有一些工作要做,主要是为图标做一个选择器,并确保相等的水平分布,但你明白了.就我而言,我正在使用片段,但相同的主体应该适用于标准选项卡视图.

在此输入图像描述


Hub*_*ert 1

这可能不完全是您正在寻找的(这不是将选项卡发送到屏幕底部的“简单”解决方案),但仍然是一个有趣的替代解决方案,我想向您指出:

ScrollableTabHost的设计与 TabHost 类似,但具有额外的滚动视图以适应更多项目...

也许深入研究这个开源项目你会找到你的问题的答案。如果我看到任何更容易的事情,我会回来找你。