2

I am implementing Collapsable toolbar. my layout is like

<CoordinatorLayout>

    <AppBarLayout>
        <CollapsingToolbarLayout>
            <ImageView/>
            <Toolbar/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clipToPadding="false"
     android:background="@android:color/white">

     <FrameLayout
         android:id="@+id/container_body"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

   </android.support.v4.widget.NestedScrollView>

</CoordinatorLayout>

problem is if i inflate fragment inside FrameLayout it takes full screen which i don’t want.

i tried putting dummy LinearLayout in place of FrameLayout giving hardcoded height it works fine

xml Code :

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/text_grey_color">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:expandedTitleGravity="center_horizontal|top"

            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary"
            android:fitsSystemWindows="true">

         <include layout="@layout/profile_detail_include_layout"
             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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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




        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:background="@android:color/white"
            android:fillViewport="true"

            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/container_body"/>


        </android.support.v4.widget.NestedScrollView>



    <de.hdodenhof.circleimageview.CircleImageView

        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/jack_example"
        android:id="@+id/circleView"
        app:civ_border_width="2dp"
        app:layout_anchor="@id/collapsing_toolbar"
        app:layout_anchorGravity="bottom|center"
        app:theme="@style/ThemeOverlay.AppCompat.Light"
        app:civ_border_color="@android:color/white"/>


</android.support.design.widget.CoordinatorLayout>
Jolson Da Costa
  • 1,095
  • 1
  • 12
  • 31
  • FrameLayout places its children in layers stacked as per the hierarchy. To do what you want to do you should inflate the fragment inside a LinearLayout which resides inside a framelayout. – Nishant Srivastava Dec 22 '15 at 06:21
  • Tried not working. same problem – Jolson Da Costa Dec 22 '15 at 06:46
  • When you say it takes Full Screen does that mean you don't see AppBar with Toolbar and Imageview inside it? – PunitD Dec 22 '15 at 06:57
  • Can you put down your complete xml code over here? – PunitD Dec 22 '15 at 07:02
  • what is `layout_height` property of `profile_detail_include_layout's` parent? And What are you trying populate inside your Fragment? Could it be of fixed height? – PunitD Dec 22 '15 at 07:24
  • height is static of `profile_detail_include_layout` and in my fragment i will be having `tabLayout` with `viewPager` – Jolson Da Costa Dec 22 '15 at 07:27
  • Then the above xml should atleast show you Toolbar with profile layout if not the fragment below it..can you also post your `profile_detail_include_layout's` xml? – PunitD Dec 22 '15 at 07:42
  • [Please see this StackOverflow answer](http://stackoverflow.com/questions/31033242/appbarlayout-nestedscrollview-framelayout-what-is-the-deal) – Ilanthirayan Paramanathan May 01 '17 at 11:52

1 Answers1

0

try this code

<android.support.v4.widget.NestedScrollView 
 android:id="@+id/scroll"
 app:layout_behavior="@string/appbar_scrolling_view_behavior"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:clipToPadding="false"
 android:background="@android:color/white">

   <RelativeLayout 
     android:id="@+id/relative_layout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     >
 <FrameLayout
     android:id="@+id/container_body"
     android:layout_width="match_parent"
     android:layout_height="match_parent" />
   </RelativeLayout>

and then specify the size of FrameLayout

S. Alawadi
  • 144
  • 1
  • 6