How to put Google Maps V2 on a Fragment using ViewPager

前端 未结 13 1967
攒了一身酷
攒了一身酷 2020-11-22 04:56

I am trying to do a tab layout same in Play Store. I got to display the tab layout using a fragments and viewpager from androidhive. However, I can\'t implement google maps

相关标签:
13条回答
  • 2020-11-22 05:50

    This is the Kotlin way:

    In fragment_map.xml you should have:

    <?xml version="1.0" encoding="utf-8"?>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    In your MapFragment.kt you should have:

        private fun setupMap() {
            (childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?)!!.getMapAsync(this)
        }
    

    Call setupMap() in onCreateView.

    0 讨论(0)
提交回复
热议问题