krialix
krialix

Reputation: 125

AppBarLayout with Linear Layout

I have the following style

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

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

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="@dimen/app_bar_height"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/profile_girl"
            app:layout_collapseMode="parallax"
            tools:ignore="ContentDescription" />

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

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

    <RelativeLayout
        android:id="@+id/layout_profile_info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/white"
        android:paddingBottom="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="32dp"
        app:layout_collapseMode="parallax">

        <TextView
            android:id="@+id/profile_username_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="Real Name"
            android:textAppearance="@style/TextAppearance.AppCompat.Title"
            android:textColor="?android:attr/textColorPrimaryInverse" />

        <LinearLayout
            android:id="@+id/profile_count_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_username_text"
            android:orientation="horizontal"
            android:paddingBottom="8dp"
            android:paddingTop="8dp">

            <TextView
                android:id="@+id/posts_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/posts_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="POSTS"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorSecondaryInverse" />

            <TextView
                android:id="@+id/following_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/following_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:text="FOLLOWING"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorSecondaryInverse" />

            <TextView
                android:id="@+id/followers_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="4dp"
                android:text="45"
                android:textColor="?android:attr/textColorPrimaryInverse"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/followers_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="FOLLOWERS"
                android:textAppearance="@style/TextAppearance.AppCompat.Caption"
                android:textColor="?android:attr/textColorPrimaryInverse" />

        </LinearLayout>

        <TextView
            android:id="@+id/profile_desc_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profile_count_layout"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="One must hear the karma in order to develop the doer of unbiased joy."
            android:textColor="?android:attr/textColorSecondaryInverse" />

    </RelativeLayout>

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

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

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

<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:layout_margin="16dp"
    android:src="@drawable/profile_avatar"
    app:civ_border_color="#FFFFFFFF"
    app:civ_border_width="2dp"
    app:layout_anchor="@id/toolbar_layout"
    app:layout_anchorGravity="bottom|left" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_person_add_white_24dp"
    app:layout_anchor="@id/toolbar_layout"
    app:layout_anchorGravity="bottom|end" />

This layout generates

enter image description here
I want to get following behaviour:

When scroll up Relative Layout goes under CollapsingToolbarLayout, at the end I must have Toolbar with TabLayout and circular profile icon and FAB must disappear.

FAB hide and show action works perfectly if I anchor it to AppBarLayout but when I anchor it to CollapsingToolbarLayout it doesn't work. Also how can I push Relative Layout under the CollapsingToolbar when I scroll up.

I tried to put Relative Layout in CollapsingToolbar but I couldn't succeed.

Upvotes: 3

Views: 1035

Answers (1)

Laveen Balakrishna
Laveen Balakrishna

Reputation: 286

Enable nested scrolling for Relative layout

RelativeLayout ref;
NestedScrollingChildHelper mNestedScrollingChildHelper = new NestedScrollingChildHelper(ref);
mNestedScrollingChildHelper.setNestedScrollingEnabled(true);

Upvotes: 1

Related Questions