我已经创建了这样的 AppBar 布局
<android.support.design.widget.AppBarLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appbar_layout"
android:layout_height="@dimen/app_bar_height"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="20dp">
<android.support.design.widget.CollapsingToolbarLayout...>
</android.support.design.widget.AppBarLayout>
它在 LinearLayout 中起作用并转换阴影:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/app_bar_large" />
</LinearLayout>
但是当我把它放到 CoordinatorLayout 中时,阴影消失了:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/app_bar_large" />
</android.support.design.widget.CoordinatorLayout>
如何让 appbar 再次显示它的影子?
最佳答案
这实际上是 CollapsingToolbarLayout
的一个实现细节,见 source code :
if (Math.abs(verticalOffset) == scrollRange) {
// If we have some pinned children, and we're offset to only show those views,
// we want to be elevate
ViewCompat.setElevation(layout, layout.getTargetElevation());
} else {
// Otherwise, we're inline with the content
ViewCompat.setElevation(layout, 0f);
}
当 CollapsingToolbarLayout
显示非固定元素时会移除高度 - 默认情况下,只有固定子元素可见时才会显示高度。
关于android - CoordinatorLayout 和 AppBarLayout 高程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34139230/