android - 谷歌地图和协调器布局

标签 android google-maps android-coordinatorlayout

我正在尝试模仿谷歌地图布局。他们似乎使用了带有 map fragment 的协调器布局。问题是:

1 - 我无法设置底部 View 的最小值(见图 1 和图 3)。

2 - 我需要最大程度的折叠,我总是想显示 map 的一部分(图 2)

3 - 如果我过度折叠 map ,FAB 和 map 就会消失。

Google maps picture 1 Google maps picture 2 My app picture 3 My app picture 4 My app picture 5

代码:

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlways" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_camera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:clickable="true"
        android:src="@drawable/ic_photo_camera_white"
        app:backgroundTint="@color/colorPrimary"
        app:fabSize="normal"
        app:layout_anchor="@+id/appbar"
        app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>

最佳答案

对于第 3 个屏幕截图,作为最小高度,您可以这样做:

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

对于屏幕截图 5,使用空工具栏设置最小高度。

看看下一个示例:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:id="@+id/appBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true">

        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"/>

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragment_container">

    </FrameLayout>

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="-60dp"
    android:layout_marginRight="16dp"
    android:src="@android:drawable/ic_dialog_email"
    app:layout_anchor="@id/appBar"
    app:layout_anchorGravity="bottom|right|end"  />

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

关于android - 谷歌地图和协调器布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35354539/

相关文章:

Android:如何以编程方式打开和关闭屏幕?

android - 具有用于定位的可选/条件关系的 RelativeLayout

ios - 如何在 swift 3 中使用 autocompleteBounds

api - 在 Google map 上显示用户头像和姓名

android - 使用 ConstraintLayout 和 CoordinatorLayout 在滚动时设置动画

java - 单击通知中的按钮时启动 Activity

android - ProgressBar 高度=match_parent

android - 来自图像 URL GoogleMap API V2 的自定义标记图标

android - 弹出菜单显示时工具栏滚动

java - F.A.B 隐藏但不显示