2017-12-24 22 views
0

アクティビティに表示されるサポートマップの一部があります。ただし、フローティングアクションボタンは表示されません。私は非常に多くの方法を試みましたが、私はどこにもいません。フローティングアクションボタンが表示される

<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) 

すべてのヘルプは大幅に

EDIT評価されて:私のために働いたものを最後にを問題は、あなたがフラグメントを追加することである

val mapFragment = this.childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment 
    mapFragment.getMapAsync(this) 
+0

のように新しいフラグメントを追加でframeLayoutとXMLでフラグメントを置き換える代わりでframeLayoutのRelativeLayoutを使用してみてくださいので、 FABはその断片の下に横たわっています... –

+0

あなたの返事をありがとう。これは私にとってはうまくいかなかった。 – SachchaDroid

+0

FrameLayoutに2人の子供がいますか? –

答えて

0

ました2回、xmlから1回、次にコードでもう一度。フラグメントトランザクションのコードを削除し、代わりにfindFragmentByIdを使用してフラグメントを見つけて更新してください。

val mapFragment = mainAct.supportFragmentManager.findFragmentById(R.id.map_fragment) as SupportMapFragment 
mapFragment.getMapAsync(this.mainAct) 

それとも、コードでそれを行うにしたい場合は、単にfragment_container、それを呼び出すと、この

val mapFragment = SupportMapFragment() // use the apropriate constructor 
fragmentTransaction.add(R.id.fragment_container, mapFragment) 
+0

ご返信ありがとうございます。何らかの理由であなたのソリューションを試してみましたが、フローティングアクションボタンが表示されません。私はそれがレイアウトの下にあると仮定します。だから私はフラグメント内にフラグメントを持つために子フラグメントマネージャを使わなければなりませんでした。 – SachchaDroid

関連する問題