fragment anchored to appbarlayout

255 Views Asked by At

I want to achieve a UI in which the fragment should be anchored to appbarlayout. What I've done so far is, I've set anchor-gravity to my fragment second_container as bottom|center and transacted one fragment inside 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"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"

        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


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

    <FrameLayout
        android:id="@+id/second_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|center"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed" />

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.NestedScrollView>


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

The output should be like this:

desired output


what I'm getting is:

current output

As you can see, the fragment content is getting overlapped on appbarlayout, what is the problem here? Thanks for your attention.

0

There are 0 best solutions below