2015-03-03 32 views
0

我那里有一个TextView一个非常简单的应用程序和ButtonRelativeLayout的(与背景图像):造成帧背景图像跳过

<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

没有你添加的硬件在AndroidManifest文件加速=真的吗? – Rustam 2015-03-03 04:54:38

+0

@Rustam我刚刚做到了。没有太大的区别。另外,据我所知,这对老款Android手机无效。 – 2015-03-03 05:08:42

+0

您是否在'drawable-?dpi'文件夹中针对不同分辨率缩放了图像?这将优化图像加载。 – Lamorak 2015-03-03 07:15:38

回答

1

发生这种情况是因为您正在加载大尺寸图像。尝试优化它的分辨率。

1px的= 4字节的内存

通过这个你可以来了解你的应用程序有多少获得对存储器

+0

在最大的屏幕尺寸上,最小的尺寸仍然看起来不错?我不希望图像质量降低在大屏幕尺寸 – 2015-03-03 05:09:20

+0

检查此http://stackoverflow.com/questions/26565127/imageview-skipped-frames这家伙试图加载asyntask中的图像,它为他工作 – Fahim 2015-03-03 05:20:41