我有一个非常简单的应用,只有TextView
和Button
RelativeLayout
(带有背景图片):
<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=".MainActivity"
android:background="@drawable/background_image" >
<!-- text in top left of background -->
<TextView android:text="App" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- primary button that outputs audio -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="trueButtonClick" />
</RelativeLayout>
onClick
事件只播放一些音频:
public void trueButtonClick(View v) {
//create media player
MediaPlayer mp = MediaPlayer.create(this, R.raw.audio_test);
//make noise
mp.start();
}
在logcat中,我收到以下消息:
03-02 23:41:40.063 1910-1910/com.example.mohammad.trueapp E/MediaPlayer﹕ Should have subtitle controller already set
03-02 23:41:40.063 1910-1910/com.example.mohammad.trueapp I/Choreographer﹕ Skipped 210 frames! The application may be doing too much work on its main thread.
03-02 23:41:43.961 1910-1910/com.example.mohammad.trueapp I/Choreographer﹕ Skipped 232 frames! The application may be doing too much work on its main thread.
03-02 23:45:05.506 1910-1910/com.example.mohammad.trueapp I/Choreographer﹕ Skipped 115 frames! The application may be doing too much work on its main thread.
03-02 23:45:07.279 1910-1910/com.example.mohammad.trueapp E/MediaPlayer﹕ Should have subtitle controller already set
03-02 23:45:07.323 1910-1910/com.example.mohammad.trueapp I/Choreographer﹕ Skipped 108 frames! The application may be doing too much work on its main thread.
03-02 23:45:10.490 1910-1910/com.example.mohammad.trueapp E/MediaPlayer﹕ Should have subtitle controller already set
当我删除背景图片@drawable/background_image
时,应用程序会加速。然而,在添加背景图像之后,应用程序非常慢,从用户的角度来看似乎已经破坏了。背景图片大小为1040x851。有没有办法可以加快速度,防止剧烈滞后?
答案 0 :(得分:1)
这种情况正在发生,因为您正在加载大尺寸图像。尝试优化它的分辨率。
1px = 4字节内存
通过这个你可以知道你的应用程序占用了多少内存