Android 碎片';s选项卡上的内容';表格中的文本

Android 碎片';s选项卡上的内容';表格中的文本,android,android-tablayout,Android,Android Tablayout,我正在使用TabLayout并附加两个选项卡 tabLayout.addTab(tabLayout.newTab().setText("Featured")); tabLayout.addTab(tabLayout.newTab().setText("Filter")); 然后,onTabSelected()I根据用户选择的选项卡显示所需的片段 我的活动布局如下: <LinearLayout xmlns:android="http://schemas.andr

我正在使用TabLayout并附加两个选项卡

    tabLayout.addTab(tabLayout.newTab().setText("Featured"));
    tabLayout.addTab(tabLayout.newTab().setText("Filter"));
然后,
onTabSelected()
I根据用户选择的选项卡显示所需的片段

我的活动布局如下:

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/ll_container" 
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:layout_height="match_parent">


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

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

</LinearLayout>

正如您所看到的,片段的内容与选项卡的文本重叠,而它应该出现在下面。
谢谢

最后,我找到了这个问题的替代解决方案

您可以在每个选项卡片段的布局上提供顶部填充

例如

android:paddingTop=“?属性/actionBarSize”

例如,我的第一个选项卡xml如下所示:

<android.support.design.widget.CoordinatorLayout 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="wrap_content"
    android:paddingTop="?attr/actionBarSize"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.upgautam.uddhav.productassignment.uicontrollers.ProductListFragment">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/product_list_string" />

</android.support.design.widget.CoordinatorLayout>

FrameLayout
@Mohit中使用
RelativeLayout
作为perent视图和
android:layout\u下的
属性。它只是尝试了一下,但没有起作用。将代码发布到调用片段的地方
<android.support.design.widget.CoordinatorLayout 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="wrap_content"
    android:paddingTop="?attr/actionBarSize"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.upgautam.uddhav.productassignment.uicontrollers.ProductListFragment">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/product_list_string" />

</android.support.design.widget.CoordinatorLayout>