【发布时间】:2014-07-29 10:27:41
【问题描述】:
情况是我使用 Fragments 在主要活动中显示 2 个视图,这意味着我有两个选项卡,在第二个选项卡中我使用以下代码显示谷歌地图
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
RelativeLayout dashboardMapview = (RelativeLayout) inflater.inflate(R.layout.dashboard_mapview, container, false);
return dashboardMapview;
}
}
这是第二个选项卡,我想自定义地图,我在上面的函数中使用了这个代码。
imap = SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
imap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
imap 是在创建时声明的 Google Map 变量。
问题是 getSupportFragmentManager 显示错误。 此外,我对没有选项卡但只有地图的活动使用了相同的代码,它工作正常。
请注意,如果我不使用上述代码进行自定义,我可以在运行时成功显示谷歌地图。唯一的问题是定制。
我的dashboardMapview.xml 看起来像这样:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
class="com.google.android.gms.maps.SupportMapFragment" />
如果没有选项卡但只有一个活动,xml 也可以正常工作。
我正在使用 Google Maps API V2
如果它有任何意义,我认为这是因为我已经膨胀并返回了一个 RelativeLayout,但片段在其中。
关于如何自定义 googlemap 的任何想法,在单击活动中的第二个选项卡时使用该地图?
【问题讨论】:
-
我猜你得到一个空指针,对吧?
-
好吧,其实 eclipse 不允许我写那个,我无法编译代码。 Eclipse 给出了一些建议,但没有奏效
-
请发布错误然后
标签: android google-maps android-fragments google-maps-android-api-2