Android TablLayout中嵌套片段布局不当膨胀

Android TablLayout中嵌套片段布局不当膨胀,android,android-fragments,android-tablayout,Android,Android Fragments,Android Tablayout,所以我有一个主要的活动与抽屉布局。此活动具有FrameLayout,它使用fragment_forecast的布局进行膨胀。Fragment_forecast已发布,其中包含其他三个片段。所有这些子片段布局都与TabLayout的选项卡重叠 我尝试在fragment_forecast中使用LinearLayout而不是FrameLayout,但结果是子_片段的底部被切断 处理这种情况的正确方法是什么 主要活动的活动布局: 片段\日\预测的片段布局: 试试这一串代码。将FragmentLayou

所以我有一个主要的活动与抽屉布局。此活动具有FrameLayout,它使用fragment_forecast的布局进行膨胀。Fragment_forecast已发布,其中包含其他三个片段。所有这些子片段布局都与TabLayout的选项卡重叠

我尝试在fragment_forecast中使用LinearLayout而不是FrameLayout,但结果是子_片段的底部被切断

处理这种情况的正确方法是什么

主要活动的活动布局:

片段\日\预测的片段布局:


试试这一串代码。将FragmentLayout替换为RelativeLayout,并将viewpager设置在id选项卡下方

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_below="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

</RelativeLayout>
TabLayout与ViewPager片段重叠,因为片段的父项\u day\u forecast是

框架布局 表格布局 寻呼机 其中FrameLayout旨在将一个视图置于另一个视图之上

您需要将RelativeLayout用作父视图。i、 设置视图之间的关系。在这种情况下,它将是TabLayout下面的ViewPager。 比如说天气预报

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.daza.soundmap.ForecastFragment">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@color/primaryLightColor"
    app:tabIndicatorColor="@color/secondaryColor"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/primaryTextColor"
    app:tabTextColor="@color/primaryTextColor" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tabs" />
</RelativeLayout>

如果有帮助的话,请投票支持这个答案。快乐编码!
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.daza.soundmap.DayForecastFragment"
   >

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout_hour"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_hour_forecast"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical" />
    </android.support.v4.widget.SwipeRefreshLayout>

</android.support.constraint.ConstraintLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="fixed" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_below="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.daza.soundmap.ForecastFragment">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabBackground="@color/primaryLightColor"
    app:tabIndicatorColor="@color/secondaryColor"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/primaryTextColor"
    app:tabTextColor="@color/primaryTextColor" />

<android.support.v4.view.ViewPager
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tabs" />
</RelativeLayout>