【发布时间】:2016-03-18 12:31:28
【问题描述】:
我有许多在详细信息片段上使用 CollapsingToolbarLayout 的应用程序,但我试图将其放在 List (RecyclerView) 片段上。在 RecyclerView 片段上,工具栏在 CTL 上方是不透明的,而不是透明并允许图像显示在下方。
Fragment 放置在 FrameLayout 中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/application_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
<FrameLayout
android:id="@id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"/>
</RelativeLayout>
片段布局文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light">
<android.support.design.widget.AppBarLayout
android:id="@id/appbar_layout"
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"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@id/toolbar_image"
android:src="@drawable/header_image"
android:contentDescription="@string/header_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
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:background="@color/colorPrimaryTransparent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:clickable="true" />
</android.support.design.widget.CoordinatorLayout>
在 Android Studio 中,设计器看起来不错,而且应该如此(图 1);但在我的手机和模拟器上,它看起来像(图 2)。
图片 1 - AS 设计布局
图片 2 - 手机 SS
【问题讨论】:
-
@color/colorPrimaryTransparent的值是多少? -
它的 #00brown,我现在忘记了确切的数字。我不得不走开,这让我发疯了。
-
我认为这可以满足您的需求。作为旁注,您应该将 RecyclerView 放入 NestedScrollView
-
不确定 NSV 能否正常工作。 [我想我提到过,不记得]我有两个片段,一个带有 RecyclerView(列表),一个带有 NestedScrollView(详细信息),工具栏显示在它们上方。我可以试一试,但这并不能解释为什么我的细节片段显示相同。我非常感谢您的帮助,这让我今晚发疯了,但我不认为 Actionbar 链接是相同的,因为我正在尝试使用应该可以正常工作的支持/设计视图。谢谢。
-
好的,但是您正在尝试使用淡入纯色的图像来实现折叠工具栏,对吧?
标签: android toolbar android-collapsingtoolbarlayout