ogoldbart3
ogoldbart3

Reputation: 273

How to stick a view element below a collapsingtoolbarlayout toolbar in android?

trying to build an Android app with a collapsingtoolbarlayout and a view element that always sticks directly below the bottom of the toolbar.

I think I'm just messing up my organization within the whole appbarlayout, but I can't seem to figure out the right ordering.

Any help would be great! Thanks-

Here's my Activity xml

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:collapsedTitleTextAppearance="@style/CollapsedTheme"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleGravity="center|bottom"
            app:expandedTitleMarginBottom="20dp"
            app:expandedTitleMarginEnd="20dp"
            app:expandedTitleMarginStart="20dp"
            app:expandedTitleTextAppearance="@style/ExpandedTheme"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:theme="@style/ToolbarColoredBackArrow">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="180dp"
                android:orientation="vertical">

            </LinearLayout>

            <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>
    </android.support.design.widget.AppBarLayout>

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

And I'm trying to add in

    <RelativeLayout
        android:layout_below="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:background="@color/blue"/>

So that it always stays below the toolbar, but when the collapsingtoolbarlayout scrolls to the top of the screen, it stays sticking below it.

Upvotes: 5

Views: 3197

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199805

An AppBarLayout extends LinearLayout - just add your RelativeLayout below your CollapsingToolbarLayout and don't include any layout_scrollFlags.

<AppBarLayout>
  <CollapsingToolbarLayout />
  <RelativeLayout />
</AppBarLayout>

Upvotes: 11

Related Questions