【问题标题】:How to make CollapsingToolbarLayout disappear completely after scrolling?滚动后如何使 CollapsingToolbarLayout 完全消失?
【发布时间】:2021-09-04 06:10:33
【问题描述】:

我正在尝试制作一个带有两个工具栏和它们之间的水平滚动视图的片段“头部”。我想让水平滚动视图在向下滚动后完全消失,但在滚动后有一些黑色空间,我不知道为什么。我应该输入什么属性来实现它?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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_height="match_parent"
    android:layout_width="match_parent">


    <androidx.appcompat.widget.Toolbar
        android:id="@+id/tool"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:foregroundGravity="center"
            android:src="@drawable/ic_arrow" />

    </androidx.appcompat.widget.Toolbar>


    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:clipToPadding="false"
        android:fitsSystemWindows="true"
        app:layout_constraintTop_toBottomOf="@id/tool"
        tools:context=".ui.menu.MenuFragment">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="220dp"
            android:fitsSystemWindows="true"
            android:theme="@style/Theme.PizzaTime.AppBarOverlay">


            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

                <HorizontalScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">
                    </LinearLayout>
                </HorizontalScrollView>

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/support_action"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:layout_gravity="bottom"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/Theme.PizzaTime.PopupOverlay">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"/>

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:foregroundGravity="center"
                        android:src="@drawable/ic_arrow" />

                </androidx.appcompat.widget.Toolbar>
            </com.google.android.material.appbar.CollapsingToolbarLayout>


        </com.google.android.material.appbar.AppBarLayout>

        <include layout="@layout/scroll_content" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

  • 您能否在您的问题中提供Theme.PizzaTime.PopupOverlayscroll_content 以及任何其他相关内容,以便我们最终重现问题。
  • 它来自标准滚动活动预设

标签: android layout android-collapsingtoolbarlayout android-appbarlayout


【解决方案1】:

在我从 CoordinatorLayout 中删除以下行之后:

android:fitsSystemWindows="true"

它开始正常工作,希望对某人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-09
    相关资源
    最近更新 更多