android - FragmentTabHost 选项卡重叠选项卡内容

标签 android android-fragments android-support-library

我正在使用 FragmentTabHost(支持库,Android)将我的 fragment 加载到选项卡中。但是,我看到选项卡托管在我的选项卡内容上。但我希望我的选项卡内容位于选项卡下方。这怎么可能?

我进行了搜索,但找不到与此相关的任何内容。

最佳答案

设置边距或填充不起作用,因为正如您在评论中所说,选项卡的大小可能会有所不同,并且该解决方案取决于 TabHost 的高度是否恒定。

我已经在这里回答了这个问题:FragmentTabHost content filling remaining space

您不需要在 Tabhost 中拥有用于 fragment (选项卡内容)的容器,当您这样做时,您将使用相同的空间来容纳 fragment 的内容和选项卡本身。

只需将 Tabhost 放在垂直 LinearLayout 内,然后将 FrameLayout 放在 TabHost 下方的外部,就像下面的示例所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TabWidget 
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"/>
    </android.support.v4.app.FragmentTabHost>

    <FrameLayout 
        android:id="@+id/realtabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</LinearLayout>

关于android - FragmentTabHost 选项卡重叠选项卡内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28201370/

相关文章:

java - 无法解析符号 'FragmentCompat' - Camera2VideoJava - 目标为 API 29

android - 返回 Android 设备的所有可用 IP 地址?

android - 插页式错误android无法暂停 Activity

android - AppBarLayout.setExpanded(boolean, true) 支持库 23.1.1 中的奇怪动画

android - 找不到 libsupportjni.so 引用的符号 __isnanf

Android 圆圈操作

Android Fragments 变化

java - 尝试使用 fragment 中的 Bundle 调用虚拟方法 java.util.ArrayList

android - 无法在 Android 水平 ListView 中随图像滚动

android - 使用 RowsFragment 时,ObjectAdapter.setPresenterSelector 有什么作用吗?