CoordinatorLayout leaves empty space at the bottom after scrolling
A

3

19

I am trying to implement Google's newest design tricks with CoordinatorLayout and have problems with scrolling and parallax effect.

After Activity is displayed, everything looks ok but the problem occurs when I try to scroll. It seems the bottom View is not expanded correctly and after it's scrolled up, empty space appears below. Bottom View seems to be big only how much it has on initial display between top View and nav bar.

It looks something like this:

enter image description here

Relevant code:

<FrameLayout 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">

<CoordinatorLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleMarginStart="72dp"
            app:expandedTitleMarginEnd="16dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"/>
        </CollapsingToolbarLayout>
    </AppBarLayout>

    <ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</CoordinatorLayout>
</FrameLayout>

This weird behavior happens randomly. Sometimes bottom View is scrollable normally and that empty space doesn't appear. What am I doing wrong? Thanks.

Amundsen answered 22/9, 2015 at 21:11 Comment(5)
have you found any solutions for this?Jerol
@goonerDroid, I didn't. At the end I stopped using Google's library.Amundsen
I feel this is the intended behavior of the co-ordinator layout.Not sure though.Jerol
@goonerDroid No, whatsapp doesn't leave empty patch at bottom.Greenwald
It seem to work to wrap the view pager in a linear layout give it gravity in a similar issueShuffle
Y
15

I had the same problem and I noticed that every layout with this problem had

android:fitsSystemWindows="true"

on CoordinatorLayout

Removing it fixed my problem everywhere.

Yahairayahata answered 15/1, 2016 at 9:38 Comment(2)
Ok now working. I was using RecyclerView instead of ViewPager, I just made it match_parent. Now it's working.Cleome
it worked. i removed this line from AppBarLayout and CollapsingToolbarLayout and its now workingEdmonds
S
1

Try to add Toolbar inside yours CollapsingToolbarLayout:

 <android.support.design.widget.CollapsingToolbarLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>
...
</android.support.design.widget.CollapsingToolbarLayout>

Also try to add

android:minHeight="?attr/actionBarSize"

to Toolbar CollapsingToolbarLayout and AppBarLayout

Schnorrer answered 22/9, 2015 at 22:24 Comment(0)
V
0

For navigational flags reasons android:fitsSystemWindows="true" did not meet my needs.

After some playing around I found that adding another CollapsingToolbarLayout with 0dp hieght does the trick.

<android.support.design.widget.CollapsingToolbarLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_scrollFlags="scroll|snap" />
Volgograd answered 5/1, 2017 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.