当动画开始播放时,我的应用程序会出现outofmemory
异常。我该怎么办?
动画中的图像组合大小为512kb,共10张图片。
我的活动类是button_anime
。
public class Button_Anime extends Activity{
private static int SPLASH_TIME_OUT = 500;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_about);
ImageView loading =(ImageView) findViewById(R.id.iVArcRail_2);
loading.setBackgroundResource(R.drawable.about_button_anime);
AnimationDrawable load =(AnimationDrawable)loading.getBackground();
load.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(Button_Anime.this, Home.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}
我的
activity_splash_about.xml
文件。 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/withoutlogo" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="70dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/logoline" />
<ImageView
android:id="@+id/iVArcRail_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView1"/>
</RelativeLayout>
这是动画文件。
about_button_anime
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/ab1"
android:duration="50"/>
<item
android:drawable="@drawable/ab2"
android:duration="50"/>
<item
android:drawable="@drawable/ab3"
android:duration="50"/>
<item
android:drawable="@drawable/ab4"
android:duration="50"/>
<item
android:drawable="@drawable/ab5"
android:duration="50"/>
<item
android:drawable="@drawable/ab6"
android:duration="50"/>
<item
android:drawable="@drawable/ab7"
android:duration="50"/>
<item
android:drawable="@drawable/ab8"
android:duration="50"/>
<item
android:drawable="@drawable/ab9"
android:duration="50"/>
<item
android:drawable="@drawable/ab10"
android:duration="50"/>
</animation-list>
这是我的日志记录。
FATAL EXCEPTION: main
Process: com.quinoid.thomasinternational, PID: 1514
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2110)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2092)
at android.content.res.Resources.getDrawable(Resources.java:700)
at android.view.View.setBackgroundResource(View.java:15303)
at com.quinoid.thomasinternational.Button_Anime.onCreate(Button_Anime.java:19)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
我该如何启动这个动画?
我已经提供了largeHeap="true"
。