【发布时间】:2014-12-03 14:56:30
【问题描述】:
性能增强:
之前我将ALL图像保存在drawable文件夹中,这可能是地图首次加载缓慢的原因,当在屏幕上绘制标记时,图像可能不适合屏幕大小。 现在我把图片保存在drawable-mdpi、drawable-hdpi等等,应用比以前更流畅了。希望对你有帮助
原问题:
我在一个片段中创建了一个地图,源代码可以在下面找到。
地图片段在第一次加载时缓慢。如果我去任何其他片段并再次单击地图片段,它会快速加载并且不再有 slug。
谁能告诉我这里发生了什么?谢谢!
fragment_map.xml,id 是map
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />
MyMapFragment.java(包含onCreateView 和 setUpMapIfNeeded)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
rootView = inflater.inflate(R.layout.fragment_map, container, false);
} catch (InflateException e) {
/* map is already there, just return view as it is */
Log.e(TAG, "inflateException");
}
setUpMapIfNeeded();
return rootView;
}
public void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the fragment_map.
if (myMap == null) {
// Try to obtain the fragment_map from the SupportMapFragment.
myMap = ((SupportMapFragment) MainActivity.fragmentManager.findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the fragment_map.
if (myMap != null) {
setUpMap();
}
}
}
【问题讨论】:
-
你有没有想过这件事?
-
我添加了一个小(脏)修复作为答案,因为这个问题仍然存在
标签: android android-maps-v2 android-maps