Android底表

时间:2018-08-03 12:31:23

标签: android google-maps-api-3 bottom-sheet

我有一个包含片段的活动,里面有一个使用google maps api的地图,并且我想添加一个底页,该底页应自动向上移动我的位置浮动按钮,直到达到中等高度为止。

这是我的片段:

<?xml version="1.0" encoding="utf-8"?>
<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.support.v4.widget.DrawerLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.google.android.gms.maps.MapView
                android:id="@+id/mapView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/my_location_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginBottom="66dp"
                app:backgroundTint="#ffffff"
                app:elevation="6dp"
                app:layout_anchor="@id/mapView"
                app:layout_anchorGravity="bottom|right|end"
                app:pressedTranslationZ="12dp"
                app:srcCompat="@drawable/ic_my_location_black_24dp" />
        </android.support.design.widget.CoordinatorLayout>
    </FrameLayout>
</android.support.v4.widget.DrawerLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:background="@android:color/holo_blue_light"
    app:behavior_hideable="false"
    app:behavior_peekHeight="55dp"
    android:clipToPadding="true"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <FrameLayout
        android:id="@+id/job_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginBottom="2dp" />

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

我要存档类似的内容,请查看“我的位置”按钮:

https://www.youtube.com/watch?v=iwpR_uzqTq4

1 个答案:

答案 0 :(得分:0)

尝试将fabsheet锚定,并按如下所示将锚重设为top|right

<?xml version="1.0" encoding="utf-8"?>
<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.support.v4.widget.DrawerLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <com.google.android.gms.maps.MapView
                    android:id="@+id/mapView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

            </android.support.design.widget.CoordinatorLayout>
        </FrameLayout>
    </android.support.v4.widget.DrawerLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:background="@android:color/holo_blue_light"
        app:behavior_hideable="false"
        app:behavior_peekHeight="55dp"
        android:clipToPadding="true"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <FrameLayout
            android:id="@+id/job_frame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="2dp" />

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/my_location_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginBottom="66dp"
        app:backgroundTint="#ffffff"
        app:elevation="6dp"
        app:layout_anchor="@id/bottom_sheet"
        app:layout_anchorGravity="top|end"
        app:pressedTranslationZ="12dp"
        app:srcCompat="@drawable/ic_my_location_black_24dp" />

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