Solution 1 :
The first draft was without the linearlayout, but doing so the toolbar was overlapping the included layout.
You can go ahead with your first attempt, but just add a top margin that equals to the Toolbar height; which is the default ActionBar height in your case ?attr/actionBarSize
.
So, this will be:
<com.google.android.material.appbar.AppBarLayout
<com.google.android.material.appbar.CollapsingToolbarLayout
<com.google.android.material.appbar.MaterialToolbar
...
android_layout_height="?attr/actionBarSize"
<include
...
android_layout_marginTop="?attr/actionBarSize"
...
Problem :
I am trying to include a layout under the toolbar within a CollapsingToolbarLayout
.
The first draft was without the linearlayout
, but doing so the toolbar was overlapping the included layout.
So I put the toolbar and the layout into a linearlayout
. The layout is under the toolbar as intended, but the scrolling behaviour is now gone.
They just stay at the same place and don’t scroll.
<com.google.android.material.appbar.AppBarLayout
android_id="@+id/appbar"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_fitsSystemWindows="true"
app_liftOnScroll="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android_id="@+id/toolbar_layout"
style="@style/Widget.SaltWatcher.App.Toolbar"
android_layout_width="match_parent"
android_layout_height="wrap_content"
app_layout_scrollFlags="scroll|exitUntilCollapsed"
app_titleEnabled="false"
app_toolbarId="@id/toolbar">
<LinearLayout
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_orientation="vertical"
app_layout_collapseMode="pin"
app_layout_scrollFlags="scroll|exitUntilCollapsed">
<com.google.android.material.appbar.MaterialToolbar
android_id="@+id/toolbar"
style="@style/Widget.SaltWatcher.App.Toolbar"
android_layout_width="match_parent"
android_layout_height="?attr/actionBarSize"
android_elevation="0dp"
app_contentInsetStart="0dp"
app_elevation="0dp"
app_layout_collapseMode="parallax" />
<include
android_id="@+id/values"
layout="@layout/layout_values"
android_layout_width="match_parent"
android_layout_height="136dp"
android_layout_gravity="bottom"
android_scaleType="centerCrop"
app_contentInsetStart="0dp"
app_layout_collapseMode="parallax" />
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
Comments
Comment posted by problem
do you know how solve this
Comment posted by Zain
@vivekmodi This can be done using
Comment posted by vivek modi
any example please. I didn’t know how to do that. It really help me. Thanks
Comment posted by here
@vivekmodi I’m not sure if there is something online about this; but
Comment posted by vivek modi
yes I need something similar, Searchbar when focus it goes to toolbar this is fine for me. But when he swipe down searchbar goes to original position, I only want this when searchdown remove focus.