【问题标题】:Collapsing/expanding Google Maps fragment折叠/展开谷歌地图片段
【发布时间】:2016-04-06 14:00:30
【问题描述】:

我的布局顶部是谷歌地图片段,底部是 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>

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    用 MapsView 代替片段解决了它: https://www.bignerdranch.com/blog/embedding-custom-views-with-mapview-v2/

    在 CoordinatorLayout 中很容易实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2013-07-03
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多