我正在使用 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/