【发布时间】:2016-12-08 14:23:12
【问题描述】:
我在 Android Studio 中使用 Google Maps API(通过默认的 Google Maps Activity)。我启用了setMyLocationEnabled(true),但将setMyLocationButtonEnabled 设置为false,因为我想添加一个自定义浮动操作按钮,这对我来说看起来更好,用于移动到当前位置。单击标记时,API 会自动在地图片段的右下角生成指向该标记的方向按钮,但是我实现的 FAB 会覆盖这些按钮。
查看this answer 之后,我将地图片段和浮动操作按钮包裹在CoordinatorLayout 中,希望在单击标记时它会向上移动FAB,就像对小吃店所做的那样,但事实并非如此。有没有办法手动激活那个动作,或者至少用触摸事件或类似的东西来模拟它?我试图寻找在运行时移动 FAB 的方法(例如 this),但未能找到适合我的情况的解决方案。
这是活动布局的 xml,如果需要更多信息,请告诉我。提前致谢!
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="(hidden for privacy)"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/find_my_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_my_location_gray"
app:backgroundTint="@color/white"/>
</android.support.design.widget.CoordinatorLayout>
【问题讨论】:
标签: android android-fragments google-maps-android-api-2 android-coordinatorlayout floating-action-button