【发布时间】:2017-12-24 17:40:01
【问题描述】:
我有一个活动中显示的支持地图片段。但是,浮动操作按钮不可见。我已经尝试了很多方法,但我没有成功。
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context=".views.activities.MainActivity"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_current_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_location_on_white_24dp"
app:elevation="4dp"
android:visibility="visible"
app:layout_anchorGravity="bottom|right|end"/>
val fragmentTransaction = mainAct.supportFragmentManager.beginTransaction()
val mapFragment = mainAct.supportFragmentManager.findFragmentById(R.id.map_fragment) as SupportMapFragment
fragmentTransaction.replace(R.id.main_container, mapFragment)
fragmentTransaction.addToBackStack("Map Fragment")
fragmentTransaction.commitAllowingStateLoss()
mapFragment.getMapAsync(this.mainAct)
非常感谢任何帮助
编辑:最后对我有用的是
val mapFragment = this.childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
【问题讨论】:
-
请尝试使用 RelativeLayout 而不是 frameLayout,因为 FAB 位于片段下方...
-
感谢您的回复。这对我不起作用。
-
FrameLayout 中有两个孩子吗?
-
不,那是我的片段布局文件,底部有结束标签。
标签: android kotlin floating-action-button