绩效提升:
以前我将所有图像保存在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"/>
Run Code Online (Sandbox Code Playgroud)
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() …Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,将谷歌地图(api v2)显示为片段.当应用程序加载时,它会在显示地图之前显示一个空白的白色屏幕几秒钟.我已经使用了日志语句来查看延迟的位置,但我不知道它为什么这么慢.
这是我的onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate Start -------------------------------");
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate 1 -------------------------------");
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate 2 -------------------------------");
do_async_setup();
Log.i(TAG, "onCreate 3 -------------------------------");
prefs = getSharedPreferences(PREFS_NAME, 0);
prefs_editor = prefs.edit();
Log.i(TAG, "onCreate Finish -------------------------------");
Run Code Online (Sandbox Code Playgroud)
这是输出.
01-20 10:05:28.802: I/HeadsUp(19544): onCreate Start -------------------------------
01-20 10:05:28.802: I/HeadsUp(19544): onCreate 1 -------------------------------
01-20 10:05:30.396: I/HeadsUp(19544): onCreate 2 -------------------------------
01-20 10:05:30.396: I/HeadsUp(19544): onCreate 3 -------------------------------
01-20 10:05:30.403: I/HeadsUp(19544): onCreate Finish -------------------------------
Run Code Online (Sandbox Code Playgroud)
你可以看到setContentView有1.5秒的延迟.这是我的布局.
<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"
tools:context=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud)