Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Panning google map in CoordinatorLayout causes recyclerview to scroll in android design support library 23.0.1

The map is in a collapsingToolbarLayout which is nested in an appBarLayout. In versions 22.2.0 and 22.2.1 of the android design support library, I could pan around the map independently of the coordinatorLayout but in 23.0.1, if i try to pan across the map in the north/south axis, it causes the recyclerview to scroll up/down. Is this a bug or is there a way to pass the touch events from the appBarLayout to the mapFragment?

<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="match_parent"
            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"
    android:background="#44CCFF"
    app:behavior_overlapTop="184dp"
    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="bottom|right"
    android:layout_margin="16dp"
    android:src="@drawable/ic_list_white_24dp"
    app:backgroundTint="#3366FF"
    app:fabSize="normal" />

like image 305
Oliver Wheeler Avatar asked Sep 16 '15 23:09

Oliver Wheeler


1 Answers

I faced the same problem and solved it this way.

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
       @Override
       public boolean canDrag(AppBarLayout appBarLayout) {
            return false;
       }
});
params.setBehavior(behavior);
like image 102
lilienberg Avatar answered Nov 07 '22 19:11

lilienberg