首页 > 解决方案 > 折叠工具栏布局在展开时会在底部导航栏下方创建一个间隙

问题描述

我正在使用带有底部导航视图和中间的片段的折叠工具栏布局。当折叠工具栏的标题展开时,由于某种原因,底部导航视图下方有一个小间隙。我已经尝试修改fitsSystemWindows标签,但它没有解决问题。

在此处输入图像描述

但是,当标题折叠时,间隙会自动消失。

在此处输入图像描述

这是我正在使用的布局 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

    <variable
        name="viewModel"
        type="LandingViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/layout_base"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:background="?attr/colorSurface">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/bottomNavigation"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/layout_app_bar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height"
            android:background="?attr/colorSurface"
            android:fitsSystemWindows="true"
            app:expanded="true">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/layout_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:expandedTitleMarginStart="@dimen/margin_normal"
                android:minHeight="?attr/actionBarSize"
                app:contentScrim="?attr/colorSurface"
                app:elevation="0dp"
                app:layoutDescription="@xml/home_fragment_motion_scene"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:toolbarId="@+id/toolbar"
                tools:ignore="ExtraText">

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorSurface"
                    android:elevation="0dp"
                    app:layout_collapseMode="pin" />
            </com.google.android.material.appbar.CollapsingToolbarLayout>
        </com.google.android.material.appbar.AppBarLayout>

        <androidx.fragment.app.FragmentContainerView
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:navGraph="@navigation/landing_navigation" />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorSurface"
        android:clipChildren="false"
        app:itemHorizontalTranslationEnabled="false"
        app:itemIconTint="@android:color/white"
        app:itemRippleColor="@null"
        app:itemTextColor="@android:color/white"
        app:labelVisibilityMode="unlabeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/landing_bottom_navigation">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/landing_bottom_nav_layout_height"
            android:layout_gravity="center"
            android:background="?attr/colorSurface">

            <CustomAnimationButton
                android:id="@+id/btnTemplates"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:icon="@drawable/ic_baseline_templates_24"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/icCreateProject"
                app:layout_constraintTop_toTopOf="parent"
                app:selected="true"
                app:titleTextSize= "@dimen/text_size_12sp"
                app:title="@string/fgm_home_menu_title"
                app:updated="true" />

            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/icCreateProject"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:translationY="-15dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/cd_create_something_icon"
                    android:src="@drawable/ic_baseline_add_purple_outline"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <ImageView
                    android:id="@+id/newTemplateFab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/cd_create_something_icon"
                    android:src="@drawable/selector_ic_add"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />
            </androidx.constraintlayout.widget.ConstraintLayout>

            <CustomAnimationButton
                android:id="@+id/btnStories"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:icon="@drawable/ic_baseline_my_stories_24"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toRightOf="@+id/icCreateProject"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:selected="false"
                app:titleTextSize= "@dimen/text_size_12sp"
                app:title="@string/txt_my_stories"
                app:updated="false" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.bottomnavigation.BottomNavigationView>

    <!--blur background for backup template-->
    <ImageView
        android:id="@+id/ivBlurBackground"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/cd_blur_bg"
        android:elevation="8dp"
        android:visibility="gone" />
</androidx.constraintlayout.widget.ConstraintLayout>

标签: androidkotlinandroid-coordinatorlayoutandroid-collapsingtoolbarlayoutandroid-bottomnavigationview

解决方案


推荐阅读