gpt4 book ai didi

android - Mapview 显示空白但 fragment 正常

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:58:10 25 4
gpt4 key购买 nike

我正在尝试使用 Google map V2。当我使用 map fragment 时..一切正常。但是,如果我改为使用 mapview,则它会显示空白 Activity 。

有什么问题吗?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>

主要 Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

最佳答案

你需要自己初始化 map :

@Override
protected 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 显示空白但 fragment 正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26961954/

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