我有一个非常简单的应用程序,只有一个 TextView
和 RelativeLayout
内的 Button
(带有背景图像):
<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。有没有办法可以加快速度以防止严重滞后?
最佳答案
发生这种情况是因为您正在加载大尺寸图像。尝试优化其分辨率。
1px = 4 字节内存
通过这个你可以知道你的应用占用了多少内存
关于java - 背景图像导致帧被跳过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28824334/