Android的地图加载很慢/不启动加载活动所有,直到点击它 [英] Android Map loading very slow/not loading at all in started activity until clicking on it
本文介绍了Android的地图加载很慢/不启动加载活动所有,直到点击它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在开始一个新的地图活动地图加载很慢,并且不启动加载,直到点击屏幕。
When starting a new map activity the map loads really slow and doesn't start the loading until clicking the screen.
布局如下:
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.android.momintuition.DirectionsActivity">
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:paddingTop="62px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
map:uiCompass="true"
map:zOrderOnTop="true"
map:uiZoomControls="true"
android:background="#00000000" />
</RelativeLayout>
新的活动看起来是这样的:
The new activity looks like this:
public class DirectionsActivity extends AppCompatActivity implements OnMapReadyCallback {
GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_directions);
MapView mv = (MapView) findViewById(R.id.mapView);
mv.onCreate(savedInstanceState);
mMap = mv.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.map = googleMap;
CameraUpdate cameraUpdate =
CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
}
}
我是新来的Android。我缺少的东西吗?谢谢!
I am new to Android. Am I missing something? Thank you!
推荐答案
在这种情况下,问题是,我并没有实现下面的方法(即使是在文档中指定):
The problem in this case was that I didn't implement the following methods(even if it was specified in the documentation):
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
这是违反直觉我为什么这个方法可能会影响显示在地图上,但它确实解决问题。
It is counterintuitive to me why this methods might affect showing the map but it does fix the problem.
这篇关于Android的地图加载很慢/不启动加载活动所有,直到点击它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文