Search code examples
androidandroid-coordinatorlayoutandroid-appbarlayout

Coordinator layout shifts content at the height of a AppbarLayout


After including Coordinator layout in my project I have a problem. I'll post my layout.

Here is my main_layout.xml:

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

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

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"/>

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

<LinearLayout
    android:id="@+id/frame_content_keeper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Top Text"/>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/login_buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bottom text"/>
    </LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

enter image description here

I don't see textview with 'Bottom text'. Looks like it under screen. I think it is a defect.


Solution

  • It's normal because you should remove this line

    app:layout_scrollFlags="scroll|enterAlways"

    from your

    android.support.v7.widget.Toolbar

    This attribute is for when you have a list and when you will scroll down the action bar will hiding