Umer Kiani
Umer Kiani

Reputation: 3380

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>

Upvotes: 3

Views: 2088

Answers (2)

Alan Deep
Alan Deep

Reputation: 2105

I know it's an old question but let me hint you!

You have one Main activity.

You have 10 fragments.

Your Main activity can host the 10 fragments.

As Kris said, you need to keep the toolbar there, you should not move it, then just after creating your fragment, set a listener in that fragment that calls the remaining sequence of initialization inside the activity that cannot be initialized without the creating of the fragment. (Drawer+NavigationView (from activity) with CollapsingLayout containing the toolbar (in your fragment).

Upvotes: 2

kris larson
kris larson

Reputation: 30985

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>

Upvotes: 1

Related Questions