简体   繁体   中英

CoordinatorLayout inside ViewPager inside CoordinatorLayout scrolling issue

I have an outer CoordinatorLayout that has, as AppBar, the Toolbar and a TabLayout bar and, as content, a ViewPager with appbar_scrolling_view_behavior:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_content"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context=".MainActivity" >

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

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways|snap">

        </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.view.ViewPager android:id="@+id/container"
        android:layout_width="match_parent" android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />



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

When a tab is selected, the ViewPager is updated with a FrameLayout containing another CoordinatorLayout .

This one should display a collapsable Google Map fragment on top of a RecyclerView (showing a vertical list of items).

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nearby_content"
        android:layout_width="match_parent" android:layout_height="match_parent"
        tools:context=".MainActivity" >
        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true">

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

                <fragment
                    android:id="@+id/mapFragment"
                    android:name="com.google.android.gms.maps.MapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="300dp"
                    app:layout_collapseMode="parallax" />


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

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_overlapTop="184dp"

            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

The expected behavior is that when the user touches inside the map, the map itself should receive the gesture and therefore pan the view.

While if the user scrolls upwards starting the gesture from inside the visible part of the list, the list ( RecyclerView ) should slide over the collapsing Map, until the AppBar is reached. At that point further scrolling up should slide only the list.

The problem arises when the gesture is not too much slow: part of the scrolling (roughly the equivalent of the TabLayout height) is consumed by the RecyclerView before it reaches the AppBar.

Also, after scrolling all the way up the list, scrolling down first expands the map and then slides the list (leaving the first part of the list hidden), when it should do the viceversa.

Before scrolling up

After scrolling all the way up and down a bit

I'm not very sure about the answer but you can try adding android:nestedScrollingEnabled="false" inside your recycler view:

<android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_overlapTop="184dp"
            android:nestedScrollingEnabled="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM