gpt4 book ai didi

Android 无法在 fragment 中加载谷歌地图

转载 作者:行者123 更新时间:2023-11-29 00:18:08 26 4
gpt4 key购买 nike

我正在尝试在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com