【问题标题】:Why is CollapsingToolbarLayout putting a empty space under expanded content为什么 CollapsingToolbarLayout 在展开的内容下放置一个空白区域
【发布时间】:2019-04-22 20:55:10
【问题描述】:

我正在尝试使用CollapsingToolbarLayout,但在我的内容下获得了这个蓝色空间。折叠状态没有这个问题。

展开内容下的空白空间似乎等于状态栏高度。我无法理解为什么会发生这种情况。 我的xml 看起来像这样

    <android.support.design.widget.CoordinatorLayout
        android:fitsSystemWindows="true" ...>

        <android.support.design.widget.AppBarLayout
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true" ...>

            <android.support.design.widget.CollapsingToolbarLayout
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:fitsSystemWindows="true"
                  app:contentScrim="@color/colorPrimary"
                  app:layout_scrollFlags="scroll|snap|exitUntilCollapsed|enterAlwaysCollapsed"
                  app:statusBarScrim="@android:color/transparent">

                 <android.support.constraint.ConstraintLayout
                      android:id="@+id/expanded_toolbar"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:fitsSystemWindows="true"
                      app:layout_collapseMode="parallax".../>

             <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:elevation="6dp"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:navigationIcon="?attr/homeAsUpIndicator"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
                    <android.support.constraint.ConstraintLayout.../>
               </android.support.v7.widget.Toolbar>

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

更新

我暂时找到了解决办法

collapsingToolbar.post {
            val params = (collapsingToolbar.layoutParams as ViewGroup.MarginLayoutParams)
            params.height = findViewById<View>(R.id.expanded_toolbar).height
            collapsingToolbar.layoutParams = params
        }

【问题讨论】:

  • 在 CollapseToolbar 中删除 app:contentScrim="@color/colorPrimary" 并测试它是否仍然存在
  • 没有帮助。它使折叠状态工具栏的背景颜色透明,并在其下扩展状态内容。 @AliKhaki

标签: android material-design android-toolbar android-collapsingtoolbarlayout


【解决方案1】:

我认为您应该尝试将collapsing toolbarlayout_height 更改为wrap_content 而不是match_parent

我相信蓝色是因为折叠工具栏中的工具栏。所以你应该确保你的背景应用于 appbar 布局,或者折叠工具栏布局。

但是,这可能会导致问题,因为您使用的是图像背景而不仅仅是颜色。因此,我建议您跟踪折叠工具栏的状态,无论它是折叠还是打开,并相应地更新您的背景。

【讨论】:

【解决方案2】:

在 CollapsingToolbarLayout 内的约束中设置“match_parent”对我有用:

<android.support.constraint.ConstraintLayout
                      android:id="@+id/expanded_toolbar"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:fitsSystemWindows="true"
                      app:layout_collapseMode="parallax".../>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    相关资源
    最近更新 更多