折叠时CollapsingToolbarLayout显示中断的标题

标题有问题

嘿,你可以看到这张图片,我正在尝试使用CollpasingToolbarLayout,但标题没有被正确绘制。 在展开状态下,我将标题设置为淡出:

val collapsingToolbarLayout = layout.findViewById<CollapsingToolbarLayout>(R.id.collapsing_toolbar) collapsingToolbarLayout.setExpandedTitleColor(android.R.color.transparent) 

所以扩大的国家并不重要。 我的xml看起来像这样:

 <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.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" app:expanded="false" > <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp" android:fitsSystemWindows="true"> <CalendarView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="35dp"/> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" app:title="Title" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:layout_collapseMode="pin"> </android.support.v7.widget.Toolbar> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:clipToPadding="false" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <include layout="@layout/main_fragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v4.widget.NestedScrollView>> </android.support.design.widget.CoordinatorLayout> 

我可以试试吗? 我想这是一个错误,但我不知道。 谢谢

android:fitsSystemWindows="true"通常会在某些情况下添加适当的填充以确保视图不会在状态栏/导航栏下分层。 在你的情况下,我认为这是推动你的文本向下的原因。

你可能需要玩这个,但是尝试删除它为你的AppBarLayout和它的孩子,也许尝试一些不同的组合。

这也可能有助于向我们展示视图边界,以便我们可以看到实际的视图。 这可以在Android Studio预览中或通过开发人员选项完成