0
我在它后面有一个标题和一个工具栏。 向上滚动标题时,工具栏将固定在顶部。修复下面的工具栏顶部和标题
问题是,我想要标题前的工具栏,在我的活动之上,并且当我向上滚动标题时,工具栏只会改变它的颜色。
toolbar
header (when scroll, change toolbar color)
任何想法如何添加工具栏之前的标题,我的活动之上,并在滚动标题时更改其颜色?
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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">
<RelativeLayout android:id="@+id/header"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="160dp"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="0dp"
android:id="@+id/imageViewProfile"
android:adjustViewBounds="true"
android:cropToPadding="false" />
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="?attr/colorPrimaryDark" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:scrollbars="none"
android:layout_alignParentLeft="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
您的布局似乎**嵌套布局的混乱* *。你知道**嵌套布局会影响表演**,对吗?你不能**尽可能简化它吗? –
谢谢你的回答。 @Rotwang。我怎么能简化这个?我需要有一个标题和一个recyclerview并滚动到一起,我认为这是唯一的方法... –
像往常一样,有1000多种方法可以做同样的事情。我正在考虑使用工具栏/操作栏的容器(比如LinearLayout或者最适合的布局)。在它里面,你可以把一个带View的RecyclerView作为头部使用。 “标题”将与RecyclerView中的其他元素一起滚动。 –