【发布时间】:2015-09-09 07:59:51
【问题描述】:
尝试新的 android 设计库时,我发现了一个带有工具栏阴影的错误。使用 CollapsingToolbarLayout 时,工具栏下方的阴影仅在工具栏折叠时出现。当我们扩展它时,阴影消失了。我的布局看起来像
<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/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/user_avatar_height"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:tabGravity="fill"
app:tabIndicatorColor="@android:color/white"
app:tabMaxWidth="0dp"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
但是当它展开时阴影消失了。
有什么办法可以解决这个问题吗? 可能有办法处理阴影出现/消失吗? 谢谢。
【问题讨论】:
-
这可能不是一个错误——它可能意味着执行本页底部“具有重叠内容的灵活空间”下描述的行为:google.com/design/spec/patterns/…
-
您找到解决方案了吗?我认为这种行为是有意的,但如果你想要阴影,即使在扩展时也很麻烦。我试过听 AppBarLayout 偏移变化并手动设置阴影,并将 AppBarLayout 包装在 RelativeLayout 中并手动在下面放置阴影,但没有任何效果...
-
@Thoast83 在下面发布答案。
-
@RamanBranavitski 我不明白,当我问你是否找到方法时,为什么要发布答案..?但我今天居然找到了一个方法,也许有更好的方法,但它确实有效。你想让我把它作为解决方案发布吗?