折叠/展开Goog​​le地图片段

时间:2016-04-06 14:00:30

标签: android google-maps

我在顶部放置了Google Maps片段,在底部放置了ScrollView。我需要在滚动底部视图时折叠片段,就像这个例子(滚动技术4):http://code.tutsplus.com/articles/scrolling-techniques-for-material-design--cms-24435

这是我的布局。如何实现这个?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/my_appbar_container"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:background="@color/colorPrimary">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:background="@color/colorPrimary"
        app:title="Address"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="200dp">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/abc_popup_background_mtrl_mult">

                <fragment
                    android:id="@+id/autocomplete_fragment"
                    android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </FrameLayout>

    </fragment>

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

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


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/activity_horizontal_margin">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/name_label"
                    android:layout_width="@dimen/textview_with"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:text="@string/textview_name"
                    android:textColor="#000"
                    android:textSize="@dimen/textview_size" />

                <EditText
                    android:id="@+id/name"
                    android:hint="@string/edittext_hint_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@+id/name_label"
                    android:layout_toRightOf="@+id/name_label"
                    android:singleLine="true" />


            </RelativeLayout>

            ...

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            ...

            </RelativeLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

使用MapsView解决它而不是片段: https://www.bignerdranch.com/blog/embedding-custom-views-with-mapview-v2/

在CoordinatorLayout中很容易实现。