CoordinatorLayout leaves empty space at the bottom after scrolling

╄→尐↘猪︶ㄣ 提交于 2019-12-03 11:11:17

问题


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:

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.


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/32727029/coordinatorlayout-leaves-empty-space-at-the-bottom-after-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!