CoordinatorLayout里面的CoordinatorLayout里面的CoordinatorLayout滚动问题

时间:2015-11-11 14:39:46

标签: android scroll android-recyclerview android-coordinatorlayout mapfragment

我有一个外部CoordinatorLayout,作为AppBar,工具栏和TabLayout栏,以及作为内容的ViewPager 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>

选择标签后,ViewPager会更新为FrameLayout,其中包含另一个CoordinatorLayout

这个应该在RecyclerView之上显示可折叠的Google地图片段(显示垂直的项目列表)。

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

预期的行为是当用户触摸地图内部时,地图本身应该接收手势并因此平移视图。

如果用户向上滚动从列表的可见部分内部开始手势,则列表(RecyclerView)应该在折叠的地图上滑动,直到到达AppBar。此时,进一步向上滚动应该只滑动列表。

当手势不是太慢时出现问题:TabLayout在到达AppBar之前,部分滚动(大致相当于RecyclerView高度)被消耗。

此外,在向上滚动列表之后,向下滚动首先展开地图然后滑动列表(隐藏列表的第一部分),当它应该反之亦然。

Before scrolling up

After scrolling all the way up and down a bit

1 个答案:

答案 0 :(得分:0)

我不太确定答案,但是您可以尝试在回收者视图中添加android:nestedScrollingEnabled="false"

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

希望有帮助。