How to Pin toolbar in a coordinator layout using collapsing toolbar?












0















I am trying to make the toolbar appear in this layout always visible instead of it appearing only when it is scrolled out completely. I have an image inside collapsing toolbar that needs to get hidden when scrolled out fully.



This is what I tried.. Any opinion on how to achieve it?



        <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:fitsSystemWindows="true"
tools:context=".activities.Event_details">


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLayout"
app:layout_anchorGravity="top"
android:layout_gravity="top" >
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>

</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/topLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">


<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/party"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<!--

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>
-->


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main_eventdetails" />

</android.support.design.widget.CoordinatorLayout>


P.S: I also tried using the toolbar inside the collapsing toolbar but I can make only the title and button visible but I want the whole toolbar to have a colorPrimary background.



I tried these links collapsing toolbar fixed and this AppBar layout behaviour and some from the other SO threads. But nothing seems to solve my problem.










share|improve this question























  • can you add screenshot ? what you need or what's happening?

    – Abhinav Gupta
    Nov 27 '18 at 11:23











  • Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

    – sanjeev
    Nov 27 '18 at 11:42
















0















I am trying to make the toolbar appear in this layout always visible instead of it appearing only when it is scrolled out completely. I have an image inside collapsing toolbar that needs to get hidden when scrolled out fully.



This is what I tried.. Any opinion on how to achieve it?



        <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:fitsSystemWindows="true"
tools:context=".activities.Event_details">


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLayout"
app:layout_anchorGravity="top"
android:layout_gravity="top" >
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>

</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/topLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">


<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/party"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<!--

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>
-->


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main_eventdetails" />

</android.support.design.widget.CoordinatorLayout>


P.S: I also tried using the toolbar inside the collapsing toolbar but I can make only the title and button visible but I want the whole toolbar to have a colorPrimary background.



I tried these links collapsing toolbar fixed and this AppBar layout behaviour and some from the other SO threads. But nothing seems to solve my problem.










share|improve this question























  • can you add screenshot ? what you need or what's happening?

    – Abhinav Gupta
    Nov 27 '18 at 11:23











  • Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

    – sanjeev
    Nov 27 '18 at 11:42














0












0








0








I am trying to make the toolbar appear in this layout always visible instead of it appearing only when it is scrolled out completely. I have an image inside collapsing toolbar that needs to get hidden when scrolled out fully.



This is what I tried.. Any opinion on how to achieve it?



        <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:fitsSystemWindows="true"
tools:context=".activities.Event_details">


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLayout"
app:layout_anchorGravity="top"
android:layout_gravity="top" >
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>

</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/topLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">


<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/party"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<!--

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>
-->


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main_eventdetails" />

</android.support.design.widget.CoordinatorLayout>


P.S: I also tried using the toolbar inside the collapsing toolbar but I can make only the title and button visible but I want the whole toolbar to have a colorPrimary background.



I tried these links collapsing toolbar fixed and this AppBar layout behaviour and some from the other SO threads. But nothing seems to solve my problem.










share|improve this question














I am trying to make the toolbar appear in this layout always visible instead of it appearing only when it is scrolled out completely. I have an image inside collapsing toolbar that needs to get hidden when scrolled out fully.



This is what I tried.. Any opinion on how to achieve it?



        <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:fitsSystemWindows="true"
tools:context=".activities.Event_details">


<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLayout"
app:layout_anchorGravity="top"
android:layout_gravity="top" >
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>

</RelativeLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/topLayout"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">


<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/party"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>

<!--

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:id="@+id/toolbarTitle"
android:layout_centerVertical="true"
android:layout_marginEnd="?android:attr/actionBarSize"
android:textStyle="bold"
android:textSize="@dimen/page_innerheader_titletxt"
android:text="@string/app_name"/>

<TextView
android:id="@+id/save_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:textColor="@color/colorYellow"
android:layout_centerVertical="true"
android:textSize="@dimen/textsize16"
android:layout_toStartOf="@id/toolbarButton"
android:layout_marginEnd="15dp"/>

<Button
android:id="@+id/toolbarButton"
android:layout_width="60dp"
android:layout_height="30dp"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorPrimary"
android:background="@drawable/rect_yellow"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>


</android.support.v7.widget.Toolbar>
-->


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>


<include layout="@layout/content_main_eventdetails" />

</android.support.design.widget.CoordinatorLayout>


P.S: I also tried using the toolbar inside the collapsing toolbar but I can make only the title and button visible but I want the whole toolbar to have a colorPrimary background.



I tried these links collapsing toolbar fixed and this AppBar layout behaviour and some from the other SO threads. But nothing seems to solve my problem.







android android-coordinatorlayout android-collapsingtoolbarlayout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 11:10









sanjeevsanjeev

14916




14916













  • can you add screenshot ? what you need or what's happening?

    – Abhinav Gupta
    Nov 27 '18 at 11:23











  • Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

    – sanjeev
    Nov 27 '18 at 11:42



















  • can you add screenshot ? what you need or what's happening?

    – Abhinav Gupta
    Nov 27 '18 at 11:23











  • Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

    – sanjeev
    Nov 27 '18 at 11:42

















can you add screenshot ? what you need or what's happening?

– Abhinav Gupta
Nov 27 '18 at 11:23





can you add screenshot ? what you need or what's happening?

– Abhinav Gupta
Nov 27 '18 at 11:23













Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

– sanjeev
Nov 27 '18 at 11:42





Usually in collapsing toolbar with an image when you scroll, the image collapses to a toolbar(ref:medium.com/@tonia.tkachuk/…). But what I want to achieve is that the toolbar should always be fixed even before collapsing and only the image should be collapsed when scrolled.

– sanjeev
Nov 27 '18 at 11:42












1 Answer
1






active

oldest

votes


















1














Try this:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ivBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_back" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="Title"
app:layout_constraintBottom_toBottomOf="@+id/ivBack"
app:layout_constraintStart_toEndOf="@+id/ivBack"
app:layout_constraintTop_toTopOf="@+id/ivBack" />

</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll">

// Your Image View


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

// RecyclerView if required
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="128dp" />

</android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>


In this code snippet, I have created a Toolbar and CoordinatorLayout which are inside the ConstraintLayout



Toolbar contains the ConstraintLayout which set the back button and title.



CoordinatorLayout has AppBarLayout which has CollapsingToolbarLayout in which you can set you ImageView.






share|improve this answer
























  • Hello @sanjeev. Did you try the above solution?

    – Prithvi Bhola
    Nov 28 '18 at 3:07











  • I will try it now and let you know asap. Thanks man

    – sanjeev
    Nov 28 '18 at 4:07











  • Ok great. Let me know in case of any query

    – Prithvi Bhola
    Nov 28 '18 at 5:50











  • Great Solution. Works as expected! Thanks Man.. :)

    – sanjeev
    Nov 29 '18 at 3:58











  • quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

    – sanjeev
    Nov 29 '18 at 4:22











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498365%2fhow-to-pin-toolbar-in-a-coordinator-layout-using-collapsing-toolbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try this:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ivBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_back" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="Title"
app:layout_constraintBottom_toBottomOf="@+id/ivBack"
app:layout_constraintStart_toEndOf="@+id/ivBack"
app:layout_constraintTop_toTopOf="@+id/ivBack" />

</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll">

// Your Image View


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

// RecyclerView if required
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="128dp" />

</android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>


In this code snippet, I have created a Toolbar and CoordinatorLayout which are inside the ConstraintLayout



Toolbar contains the ConstraintLayout which set the back button and title.



CoordinatorLayout has AppBarLayout which has CollapsingToolbarLayout in which you can set you ImageView.






share|improve this answer
























  • Hello @sanjeev. Did you try the above solution?

    – Prithvi Bhola
    Nov 28 '18 at 3:07











  • I will try it now and let you know asap. Thanks man

    – sanjeev
    Nov 28 '18 at 4:07











  • Ok great. Let me know in case of any query

    – Prithvi Bhola
    Nov 28 '18 at 5:50











  • Great Solution. Works as expected! Thanks Man.. :)

    – sanjeev
    Nov 29 '18 at 3:58











  • quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

    – sanjeev
    Nov 29 '18 at 4:22
















1














Try this:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ivBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_back" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="Title"
app:layout_constraintBottom_toBottomOf="@+id/ivBack"
app:layout_constraintStart_toEndOf="@+id/ivBack"
app:layout_constraintTop_toTopOf="@+id/ivBack" />

</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll">

// Your Image View


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

// RecyclerView if required
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="128dp" />

</android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>


In this code snippet, I have created a Toolbar and CoordinatorLayout which are inside the ConstraintLayout



Toolbar contains the ConstraintLayout which set the back button and title.



CoordinatorLayout has AppBarLayout which has CollapsingToolbarLayout in which you can set you ImageView.






share|improve this answer
























  • Hello @sanjeev. Did you try the above solution?

    – Prithvi Bhola
    Nov 28 '18 at 3:07











  • I will try it now and let you know asap. Thanks man

    – sanjeev
    Nov 28 '18 at 4:07











  • Ok great. Let me know in case of any query

    – Prithvi Bhola
    Nov 28 '18 at 5:50











  • Great Solution. Works as expected! Thanks Man.. :)

    – sanjeev
    Nov 29 '18 at 3:58











  • quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

    – sanjeev
    Nov 29 '18 at 4:22














1












1








1







Try this:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ivBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_back" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="Title"
app:layout_constraintBottom_toBottomOf="@+id/ivBack"
app:layout_constraintStart_toEndOf="@+id/ivBack"
app:layout_constraintTop_toTopOf="@+id/ivBack" />

</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll">

// Your Image View


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

// RecyclerView if required
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="128dp" />

</android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>


In this code snippet, I have created a Toolbar and CoordinatorLayout which are inside the ConstraintLayout



Toolbar contains the ConstraintLayout which set the back button and title.



CoordinatorLayout has AppBarLayout which has CollapsingToolbarLayout in which you can set you ImageView.






share|improve this answer













Try this:



<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ivBack"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_arrow_back" />

<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:text="Title"
app:layout_constraintBottom_toBottomOf="@+id/ivBack"
app:layout_constraintStart_toEndOf="@+id/ivBack"
app:layout_constraintTop_toTopOf="@+id/ivBack" />

</android.support.constraint.ConstraintLayout>

</android.support.v7.widget.Toolbar>

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll">

// Your Image View


</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

// RecyclerView if required
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="128dp" />

</android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>


In this code snippet, I have created a Toolbar and CoordinatorLayout which are inside the ConstraintLayout



Toolbar contains the ConstraintLayout which set the back button and title.



CoordinatorLayout has AppBarLayout which has CollapsingToolbarLayout in which you can set you ImageView.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 11:44









Prithvi BholaPrithvi Bhola

1,100319




1,100319













  • Hello @sanjeev. Did you try the above solution?

    – Prithvi Bhola
    Nov 28 '18 at 3:07











  • I will try it now and let you know asap. Thanks man

    – sanjeev
    Nov 28 '18 at 4:07











  • Ok great. Let me know in case of any query

    – Prithvi Bhola
    Nov 28 '18 at 5:50











  • Great Solution. Works as expected! Thanks Man.. :)

    – sanjeev
    Nov 29 '18 at 3:58











  • quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

    – sanjeev
    Nov 29 '18 at 4:22



















  • Hello @sanjeev. Did you try the above solution?

    – Prithvi Bhola
    Nov 28 '18 at 3:07











  • I will try it now and let you know asap. Thanks man

    – sanjeev
    Nov 28 '18 at 4:07











  • Ok great. Let me know in case of any query

    – Prithvi Bhola
    Nov 28 '18 at 5:50











  • Great Solution. Works as expected! Thanks Man.. :)

    – sanjeev
    Nov 29 '18 at 3:58











  • quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

    – sanjeev
    Nov 29 '18 at 4:22

















Hello @sanjeev. Did you try the above solution?

– Prithvi Bhola
Nov 28 '18 at 3:07





Hello @sanjeev. Did you try the above solution?

– Prithvi Bhola
Nov 28 '18 at 3:07













I will try it now and let you know asap. Thanks man

– sanjeev
Nov 28 '18 at 4:07





I will try it now and let you know asap. Thanks man

– sanjeev
Nov 28 '18 at 4:07













Ok great. Let me know in case of any query

– Prithvi Bhola
Nov 28 '18 at 5:50





Ok great. Let me know in case of any query

– Prithvi Bhola
Nov 28 '18 at 5:50













Great Solution. Works as expected! Thanks Man.. :)

– sanjeev
Nov 29 '18 at 3:58





Great Solution. Works as expected! Thanks Man.. :)

– sanjeev
Nov 29 '18 at 3:58













quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

– sanjeev
Nov 29 '18 at 4:22





quick question what if I have to place a view that overlaps(that stays over both the toolbar and coordinator)??

– sanjeev
Nov 29 '18 at 4:22




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53498365%2fhow-to-pin-toolbar-in-a-coordinator-layout-using-collapsing-toolbar%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks