Android 如何在底部显示选项卡栏-带片段的选项卡

Android 如何在底部显示选项卡栏-带片段的选项卡,android,android-layout,Android,Android Layout,我正在开发一个基于tab的android应用程序,我看到“TabActivity”类已被弃用,而是使用片段来实现相同的功能,我使用了以下链接并开发了我的应用程序,现在我需要在底部显示tab栏,我尝试了几种方法,但无法正确运行 有人能在这方面帮助我吗,我的标签布局xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res

我正在开发一个基于tab的android应用程序,我看到“TabActivity”类已被弃用,而是使用片段来实现相同的功能,我使用了以下链接并开发了我的应用程序,现在我需要在底部显示tab栏,我尝试了几种方法,但无法正确运行

有人能在这方面帮助我吗,我的标签布局xml

  <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TabHost
        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:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        </LinearLayout>
    </TabHost>
</LinearLayout>

首先去掉外线布局,它没用。
然后将TabWidget放在内线布局的最后一个位置,就完成了。

不管怎样,今天底部的Tabbar是一个UX反模式


将内部线性布局方向指定为垂直,并将选项卡主体置于线性布局的最后位置


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">
    <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:background="#ff140c14">

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

            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0" />
        </LinearLayout>
    </TabHost>
</RelativeLayout>

对我来说很有用

这如何回答Sam的问题?不是。我不撒谎@NickL,只是在问题中添加相关信息。你可能是对的,底部的标签栏是一个用户体验反模式,但这并不能回答问题。将非答案如建议和其他有关问题主题的“相关”信息发布到评论中,而不是作为问题的答案。您可以使用