android - 为什么 Toolbar 会被 TabLayout 覆盖?

标签 android android-layout android-toolbar android-tablayout android-collapsingtoolbarlayout

我不知道为什么当 header 向上滚动时 Toolbar 会被 Tablayout 覆盖。 expanded header image

collapsed header image

但我只是希望它们不要像这张图片那样相互重叠 enter image description here

当页眉向上滚动并折叠时,我希望它看起来像上一张图​​片。 我该如何解决? 请帮我。 先谢谢你。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="@dimen/app_bar_height"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:id="@+id/headerBg"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:contentDescription="@string/app_name"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.7" />

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <Space
                        android:layout_width="40dp"
                        android:layout_height="40dp" />

                    <ImageView
                        android:id="@+id/profilePicture"
                        android:layout_width="@dimen/profile_pic_width"
                        android:layout_height="@dimen/profile_pic_height"
                        android:scaleType="centerCrop"
                        android:layout_gravity="center_horizontal"/>
                    <TextView
                        android:id="@+id/userName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:textStyle="bold"
                        android:textSize="14dp" />
                </LinearLayout>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:minHeight="?attr/actionBarSize"
                    android:gravity="top"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabLayout"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    app:layout_collapseMode="pin"
                    app:tabIndicatorColor="?attr/colorAccent"
                    app:tabIndicatorHeight="3dp"/>

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

        </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" />

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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#fff"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/navigation_drawer_items"
        app:itemIconTint="?attr/colorPrimary"
        app:itemTextColor="@color/black">

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

</android.support.v4.widget.DrawerLayout>

最佳答案

我一点也不确定,但可能是因为你在整个布局中使用了滚动条。只需添加一些 android:layout_marginTop,例如 60 dp。

关于android - 为什么 Toolbar 会被 TabLayout 覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41297789/

相关文章:

android - android 4.4 的标签和半透明状态栏/导航出现问题

android - BitmapFactory.decodeStream 总是返回空值

android 在布局中排列 TextView

android - 调整大小后,TextView 无法正确换行文本

android - 为什么 Material 设计中 Activity 图标和非 Activity 图标的透明度不同?

android - 如何更改工具栏导航和溢出菜单图标(appcompat v7)?

java - 检索并更新 firebase 中的子数据

android - 构建apk后的错误

android - 有 2 个可以依次展开/折叠的 CollapsingToolbarLayout

java - "Google Places"API 中保证了哪些 JSON 标签?