Search code examples
androidgoogle-mapsandroid-coordinatorlayout

How to use map fragment correctly in Collapsingtoolbarlayout


When I slide a mapview up/down in CoordinatorLayout,this map will also be expanded/collapsed.
I want the map can be up/down or the other move events to see other places. just in mapview.

How to do this. Thanks in advance.

    <android.support.v4.widget.DrawerLayout  xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/rootLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="216dp"
                >

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsingToolbarLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="40dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"><!---->

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


                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:gravity="top"
                        android:minHeight="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
                    <!--app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"-->

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


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

            <android.support.design.widget.TabLayout
                android:id="@+id/info_tabLayout"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_gravity="bottom"
                android:background="@android:color/white"
                app:layout_anchor="@+id/appbar"
                app:layout_anchorGravity="bottom"
                app:tabIndicatorColor="@android:color/background_dark" />

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



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



        <include layout="@layout/navigation" />

    </android.support.v4.widget.DrawerLayout>

Solution

  • I solved this problem . look this AppBarLayout.Behavior.DragCallback Use it to AppBarlayout and then MapFragment will work fine.

    For more detailed implementation click here..