作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 fragment 中使用 google map,但我遇到了一个我不明白的问题。
我不会在这一行加载 map :
gMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
这一行似乎总是返回 null...
我尝试使用 MapFragment 代替 SupportMapFragment,但这是不可能的。
如何解决?
解释一下为什么我想在 fragment 中显示它,因为我正在使用抽屉导航,而我的一个项目需要显示 map 。
谢谢,
编辑:我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
最佳答案
我认为您应该使用 getsupportFragmentManager
而不是 getFragmentManager
调用,否则它将始终返回 null
关于Android 无法在 fragment 中加载谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24982074/
我是一名优秀的程序员,十分优秀!