Umer Kiani Umer Kiani - 1 month ago 6
Android Question

Collapsing Toolbar Layout inside Fragment Leaves blank Space at Top

I was working on a Project and when ever i try to add a collapsing layout inside a fragment it leaves blank space at topenter image description here

As seen in picture below toolbar that is used inside activity once i add collapsing toolbar it leaves this empty space which above orange color.

Here is my code for Fragment.

<?xml version="1.0" encoding="utf-8"?>




xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">


<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_gravity="fill_vertical"
android:layout_height="220dp"
app:contentScrim="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="@android:color/transparent"
>

<ImageView
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@color/review_orange"
android:src="@drawable/icon_collabartion" />



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


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


<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="@+id/rcv_showTimings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>







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



Answer Source

First, make sure you are using one of the NoActionBar themes in AppCompat.

You need to put a Toolbar in your CollapsingToolbarLayout:

 <android.support.design.widget.CollapsingToolbarLayout
     android:layout_width="match_parent"
     android:layout_gravity="fill_vertical"
     android:layout_height="220dp"
     app:contentScrim="@android:color/transparent"
     app:layout_scrollFlags="scroll|exitUntilCollapsed"
     app:statusBarScrim="@android:color/transparent"
     >

     <ImageView
         android:layout_width="match_parent"
         android:layout_height="220dp"
         android:background="@color/review_orange"
         android:src="@drawable/icon_collabartion" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

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