为什么tablayout和actionbar在android中将空间放在片段中?

为什么tablayout和actionbar在android中将空间放在片段中?,android,android-fragments,Android,Android Fragments,说明: 我在活动中实现了一个navigationDrawer。有很多可用的片段。我为我的应用程序使用了materialDesign。 当我在活动中放置tablayout时,它并没有放置空间。当我把tablayout放在我的一个片段中时,它在我的工具栏和tablayout之间留出了空间 这是我的fragment.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://sc

说明: 我在活动中实现了一个navigationDrawer。有很多可用的片段。我为我的应用程序使用了materialDesign。 当我在活动中放置tablayout时,它并没有放置空间。当我把tablayout放在我的一个片段中时,它在我的工具栏和tablayout之间留出了空间

这是我的fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/main_background"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="@drawable/gradient"
        android:theme="@style/MyMaterialTheme.AppBarOverlay" >

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

            app:tabTextColor="@color/tab_text"
            app:tabSelectedTextColor="@color/tab_text"
            app:tabIndicatorColor="#E15E5E"
            app:tabIndicatorHeight="3dp"
            app:tabTextAppearance="@style/MyTabLayoutTextAppearance"/>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
</LinearLayout>
这是我的style.xml

<resources>

    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

    </style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

    </style>
    <style name="MyMaterialTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="MyMaterialTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="MyTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse">
        <item name="android:textSize">18sp</item>
        <item name="android:textAllCaps">true</item>
    </style>
</resources>

真的
假的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
18便士
真的
这是我的v21/Style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
        <item name="android:windowContentTransitions">true</item>
        <item name="android:windowAllowEnterTransitionOverlap">true</item>
        <item name="android:windowAllowReturnTransitionOverlap">true</item>
        <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
        <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
    </style>
</resources>

真的
真的
真的
@android:过渡/移动
@android:过渡/移动
简而言之,我在应用程序中使用了一种材料设计模式

下图是在活动内部实现的

下面的图像在片段内部实现

在上图中,我遇到了问题。我希望我的活动像片段一样


请帮我解决这个问题。

我猜上面的部分来自活动,下面的部分来自片段;因此,如果你想让它看起来是平坦的颜色,没有渐变,那么你应该删除它

android:background="@drawable/gradient"
从活动和片段布局的appbar背景来看,虽然您没有发布活动布局,但我猜其中有一行类似的内容。如果结果不会改变,那么你应该改变你使用的主题;如果你做不到,那么简单地写下

android:background="@color/color_you_want"

请回答我,我不明白这个问题。哪个空间?请参见第二张图片和第一张图片。第二张图片中的actionbar有阴影actionbar和TableLayout之间的空间。
android:background="@color/color_you_want"