导致帧背景图像被跳过

问题描述:

我有一个非常简单的应用程序只是一个的TextView 按钮 A 的RelativeLayout (与背景图像):

I have a very simple app with just a TextView and a Button inside of a RelativeLayout (with a background image):

<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 事件只是扮演一些音频:

The onClick event just plays some audio:

public void trueButtonClick(View v) {
    //create media player
    MediaPlayer mp = MediaPlayer.create(this, R.raw.audio_test);
    //make noise
    mp.start();
}

在logcat中,我得到这些消息:

In logcat, I get these messages:

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

当我删除了背景图片 @绘制/ background_image ,应用程序加速。然而,添加的背景图像后,该应用程序是如此之慢,它似乎从用户的角度来看破碎。背景图像大小为1040x851。有没有一种方法,我可以加快这为prevent激烈的滞后?

When I remove the background image @drawable/background_image, the application speeds up. However, after adding the background image, the application is so slow that it seems broken from the user's perspective. The background image size is 1040x851. Is there a way I can speed this up to prevent the drastic lag?

这是发生,因为您是要装入大尺寸图片。尝试优化它的分辨率。

This is happening because you are loading a big size image. Try to optimize the resolution of it.

1px的= 4字节的内存

1px = 4 byte memory

通过这个你可以来了解你的应用程序是多少取内存

Through this you can come to know how much your app is taking the memory