本文介绍了使用CollapsingToolbarLayout时如何在AppBarLayout和滚动内容之间插入LinearLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用带有CollapsingToolbarLayout的CoordinatorLayout.我试图将LinearLayout放在AppBarLayout下方和滚动内容的上方,并且我希望此LinearLayout始终固定在屏幕上(无论是否隐藏AppBarLayout),而不是随内容滚动.
I'm using a CoordinatorLayout with CollapsingToolbarLayout. I'm trying to put a LinearLayout below AppBarLayout and above the scrolling content, and I want that this LinearLayout stays always fixed on the screen (with AppBarLayout hidden or not), not scrolling with the content.
这可能吗?
到目前为止,我有以下代码:
So far, I have the following code:
<android.support.design.widget.CoordinatorLayout
android:layout_above="@+id/linearLayout"
tools:context="..."
android:layout_width="wrap_content"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
android:minHeight="200dp"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/imagemView"
android:layout_width="match_parent"
android:layout_height="match_parent"
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"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"
>
<ImageButton
android:id="@+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/back_button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="18dp"
android:textSize="25sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|left|end"
android:layout_margin="@dimen/fab_margin"
app:borderWidth="0dp"
app:layout_behavior="myBehavior"/>
<include
layout="@layout/content_scrolling" />
</android.support.design.widget.CoordinatorLayout>
推荐答案
到目前为止,我是通过以下方式得到的:
So far I got this by following:
<CoordinatorLayout>
<AppBarLayout>
<CollapsingToolbarLayout>
</CollapsingToolbarLayout>
</AppBarLayout>
<LinearLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout/>//Layout which will stay between CollapsingToolbarLayout and Recyler or nested scroll view
<Recycler Or Nested Scroll View/>
</CoordinatorLayout>
此处线性布局将滚动,但始终对用户可见.
Here Linear layout will scroll but it will always be visible to the user.
这篇关于使用CollapsingToolbarLayout时如何在AppBarLayout和滚动内容之间插入LinearLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!