TabLayout和Fragment之间出现奇怪的白条

问题描述 投票:0回答:4

我的布局中有一个奇怪的错误,我无法弄明白。我的Fragments和TabLayout之间出现一个白色条。我现在没有改变这段代码,也许它是Android 6.0.1中的东西(我有一个Nexus 5)。我很确定,6.0或Lollipop中没有错误。

这是一个截图:

enter image description here

这是我的Activity XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_below="@+id/tablayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="142dp"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginBottom="20dp"
            app:expandedTitleMarginEnd="48dp"
            app:expandedTitleTextAppearance="@style/ExpandedText"
            app:collapsedTitleTextAppearance="@style/CollapsedText">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"/>
            </android.support.design.widget.CollapsingToolbarLayout>
        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            android:minHeight="?attr/actionBarSize"
            android:gravity="bottom"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:tabIndicatorColor="?attr/colorPrimaryDark"/>
        </android.support.design.widget.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>

任何的想法?

更新1:

在@Abanoub Samaan的建议之后,我的布局如下:

enter image description here

更新2:

该错误也出现在运行Android 5.1.1 Lollipop的Nexus 7(2012)上。

android fragment nestedscrollview
4个回答
2
投票

不要设置CollapsingToolbarLayout的高度

android:layout_height="142dp"

替换它

android:layout_height="wrap_content"

0
投票

我想到了。

我改回了支持库的旧版本,如:

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

现在我的布局恢复正常:

enter image description here


0
投票

我有不同的情况。我会在这里分享,以防有人在那里发现它有用。

我在activity_main.xml中的结构如下:

DrawerLayout
    |_ CoordinatorLayout
        |_ Toolbar
        |_ FrameLayout

为了修复TabLayout下面出现的奇怪空间,我用RelativeLayout更改了CoordinatorLayout。


0
投票

像Abdelalim一样,我遇到了同样的问题。

在我的主要活动中

<RelativeLayout>
    <FragmenLayout></FrameLayout>
    <android.support.design.widget.BottomNavigationView><android.support.design.widget.BottomNavigationView
</RelativeLayout>

我在framelayout中渲染了一些片段。在其中一个片段中,我有一个CoordinatorLayout

android:fitsSystemWindows="true"

我刚刚删除它,它工作

© www.soinside.com 2019 - 2024. All rights reserved.