android–Mapview显示空白但片段没问题

android–Mapview显示空白但片段没问题,第1张

概述我正在尝试使用GoogleMapV2.当我使用地图片段..一切正常.但是,如果我使用mapview,则会显示空白活动.可能有什么不对?XML:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:id="@+id/

我正在尝试使用Google Map V2.当我使用地图片段..一切正常.
但是,如果我使用mapvIEw,则会显示空白活动.

可能有什么不对?
XML:

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:ID="@+ID/mapParent"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:orIEntation="vertical" >     <com.Google.androID.gms.maps.MapVIEw           androID:ID="@+ID/map"          androID:layout_wIDth="match_parent"          androID:layout_height="match_parent"/>     </linearLayout>

主要活动:

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);}

解决方法:

您需要自己初始化地图:

@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    // Gets the MapVIEw from the XML layout and creates it    MapVIEw mapVIEw = (MapVIEw) findVIEwByID(R.ID.map);    mapVIEw.onCreate(savedInstanceState);    // Gets to GoogleMap from the MapVIEw and does initialization stuff    GoogleMap map = mapVIEw.getMap();    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls    MapsInitializer.initialize(this);    mapVIEw.onResume();}
总结

以上是内存溢出为你收集整理的android – Mapview显示空白但片段没问题全部内容,希望文章能够帮你解决android – Mapview显示空白但片段没问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1114883.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存