AnimationDrawable无法加载太多图像

时间:2012-09-14 08:46:13

标签: android

main java

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;



public class AndroidAnimation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.animation1);

    ImageView myAnimation = (ImageView)findViewById(R.id.myanimation1);
    final AnimationDrawable myAnimationDrawable
        = (AnimationDrawable)myAnimation.getDrawable();

    myAnimation.post(
            new Runnable(){

                public void run() {
                    myAnimationDrawable.start();
                }
            });
}
}

xml文件

<?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/default_01_0001"
    android:duration="80"/>
<item
    android:drawable="@drawable/default_01_0002"
    android:duration="80"/>
 <item
    android:drawable="@drawable/default_01_0003"
    android:duration="80"/>
  <item
    android:drawable="@drawable/default_01_0004"
    android:duration="80"/>
   <item
    android:drawable="@drawable/default_01_0005"
    android:duration="80"/>
    <item
    android:drawable="@drawable/default_01_0006"
    android:duration="80"/>
     <item
    android:drawable="@drawable/default_01_0007"
    android:duration="80"/>
      <item
    android:drawable="@drawable/default_01_0008"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_01_0009"
    android:duration="80"/>
        <item
    android:drawable="@drawable/default_01_0010"
    android:duration="80"/>
         <item
    android:drawable="@drawable/default_01_0011"
    android:duration="80"/>
          <item
    android:drawable="@drawable/default_01_0012"
    android:duration="80"/>
           <item
    android:drawable="@drawable/default_01_0013"
    android:duration="80"/>
            <item
    android:drawable="@drawable/default_01_0014"
    android:duration="80"/>
             <item
    android:drawable="@drawable/default_01_0015"
    android:duration="80"/>
              <item
    android:drawable="@drawable/default_01_0016"
    android:duration="80"/>
               <item
    android:drawable="@drawable/default_01_0017"
    android:duration="80"/>
                <item
    android:drawable="@drawable/default_01_0018"
    android:duration="80"/>
                 <item
    android:drawable="@drawable/default_01_0019"
    android:duration="80"/>
                  <item
    android:drawable="@drawable/default_01_0020"
    android:duration="80"/>
                   <item
    android:drawable="@drawable/default_01_0021"
    android:duration="80"/>
                    <item
    android:drawable="@drawable/default_01_0022"
    android:duration="80"/>
                     <item
    android:drawable="@drawable/default_01_0023"
    android:duration="80"/>
                      <item
    android:drawable="@drawable/default_01_0024"
    android:duration="80"/>
                       <item
    android:drawable="@drawable/default_01_0025"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_03_0001"
    android:duration="80"/>
<item
    android:drawable="@drawable/default_03_0002"
    android:duration="80"/>
 <item
    android:drawable="@drawable/default_03_0003"
    android:duration="80"/>
  <item
    android:drawable="@drawable/default_03_0004"
    android:duration="80"/>
   <item
    android:drawable="@drawable/default_03_0005"
    android:duration="80"/>
    <item
    android:drawable="@drawable/default_03_0006"
    android:duration="80"/>
     <item
    android:drawable="@drawable/default_03_0007"
    android:duration="80"/>
      <item
    android:drawable="@drawable/default_03_0008"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_03_0009"
    android:duration="80"/>
        <item
    android:drawable="@drawable/default_03_0010"
    android:duration="80"/>
         <item
    android:drawable="@drawable/default_03_0011"
    android:duration="80"/>
          <item
    android:drawable="@drawable/default_03_0012"
    android:duration="80"/>
           <item
    android:drawable="@drawable/default_03_0013"
    android:duration="80"/>
            <item
    android:drawable="@drawable/default_03_0014"
    android:duration="80"/>
             <item
    android:drawable="@drawable/default_03_0015"
    android:duration="80"/>
              <item
    android:drawable="@drawable/default_03_0016"
    android:duration="80"/>
               <item
    android:drawable="@drawable/default_03_0017"
    android:duration="80"/>
                <item
    android:drawable="@drawable/default_03_0018"
    android:duration="80"/>
                 <item
    android:drawable="@drawable/default_03_0019"
    android:duration="80"/>
                  <item
    android:drawable="@drawable/default_03_0020"
    android:duration="80"/>
                   <item
    android:drawable="@drawable/default_03_0021"
    android:duration="80"/>
                    <item
    android:drawable="@drawable/default_03_0022"
    android:duration="80"/>
                     <item
    android:drawable="@drawable/default_03_0023"
    android:duration="80"/>
                      <item
    android:drawable="@drawable/default_03_0024"
    android:duration="80"/>
                       <item
    android:drawable="@drawable/default_03_0025"
    android:duration="80"/>
                           <item
    android:drawable="@drawable/default_03_0026"
    android:duration="80"/>
<item
    android:drawable="@drawable/default_03_0027"
    android:duration="80"/>
 <item
    android:drawable="@drawable/default_03_0028"
    android:duration="80"/>
  <item
    android:drawable="@drawable/default_03_0029"
    android:duration="80"/>

   <item
    android:drawable="@drawable/default_03_0030"
    android:duration="80"/>
    <item
    android:drawable="@drawable/default_03_0031"
    android:duration="80"/>
     <item
    android:drawable="@drawable/default_03_0032"
    android:duration="80"/>
      <item
    android:drawable="@drawable/default_03_0033"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_03_0034"
    android:duration="80"/>
        <item
    android:drawable="@drawable/default_03_0035"
    android:duration="80"/>

         <item
    android:drawable="@drawable/default_03_0036"
    android:duration="80"/>
          <item
    android:drawable="@drawable/default_03_0037"
    android:duration="80"/>
           <item
    android:drawable="@drawable/default_03_0038"
    android:duration="80"/>
            <item
    android:drawable="@drawable/default_03_0039"
    android:duration="80"/>
             <item
    android:drawable="@drawable/default_03_0040"
    android:duration="80"/>
              <item
    android:drawable="@drawable/default_03_0041"
    android:duration="80"/>
               <item
    android:drawable="@drawable/default_03_0042"
    android:duration="80"/>
                <item
    android:drawable="@drawable/default_03_0043"
    android:duration="80"/>
                 <item
    android:drawable="@drawable/default_03_0044"
    android:duration="80"/>
                  <item
    android:drawable="@drawable/default_03_0045"
    android:duration="80"/>
         <item
    android:drawable="@drawable/default_02_0001"
    android:duration="80"/>
<item
    android:drawable="@drawable/default_02_0002"
    android:duration="80"/>
 <item
    android:drawable="@drawable/default_02_0003"
    android:duration="80"/>
  <item
    android:drawable="@drawable/default_02_0004"
    android:duration="80"/>
   <item
    android:drawable="@drawable/default_02_0005"
    android:duration="80"/>
    <item
    android:drawable="@drawable/default_02_0006"
    android:duration="80"/>
     <item
    android:drawable="@drawable/default_02_0007"
    android:duration="80"/>
      <item
    android:drawable="@drawable/default_02_0008"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_02_0009"
    android:duration="80"/>
        <item
    android:drawable="@drawable/default_02_0010"
    android:duration="80"/>
         <item
    android:drawable="@drawable/default_02_0011"
    android:duration="80"/>
          <item
    android:drawable="@drawable/default_02_0012"
    android:duration="80"/>
           <item
    android:drawable="@drawable/default_02_0013"
    android:duration="80"/>
            <item
    android:drawable="@drawable/default_02_0014"
    android:duration="80"/>
             <item
    android:drawable="@drawable/default_02_0015"
    android:duration="80"/>
              <item
    android:drawable="@drawable/default_02_0016"
    android:duration="80"/>
               <item
    android:drawable="@drawable/default_02_0017"
    android:duration="80"/>
                <item
    android:drawable="@drawable/default_02_0018"
    android:duration="80"/>
                 <item
    android:drawable="@drawable/default_02_0019"
    android:duration="80"/>
                  <item
    android:drawable="@drawable/default_02_0020"
    android:duration="80"/>
                   <item
    android:drawable="@drawable/default_02_0021"
    android:duration="80"/>
                    <item
    android:drawable="@drawable/default_02_0022"
    android:duration="80"/>
                     <item
    android:drawable="@drawable/default_02_0023"
    android:duration="80"/>
                      <item
    android:drawable="@drawable/default_02_0024"
    android:duration="80"/>
                       <item
    android:drawable="@drawable/default_02_0025"
    android:duration="80"/>
                           <item
    android:drawable="@drawable/default_02_0026"
    android:duration="80"/>
<item
    android:drawable="@drawable/default_02_0027"
    android:duration="80"/>
 <item
    android:drawable="@drawable/default_02_0028"
    android:duration="80"/>
  <item
    android:drawable="@drawable/default_02_0029"
    android:duration="80"/>
   <item
    android:drawable="@drawable/default_02_0030"
    android:duration="80"/>
    <item
    android:drawable="@drawable/default_02_0031"
    android:duration="80"/>
     <item
    android:drawable="@drawable/default_02_0032"
    android:duration="80"/>
      <item
    android:drawable="@drawable/default_02_0033"
    android:duration="80"/>
       <item
    android:drawable="@drawable/default_02_0034"
    android:duration="80"/>
        <item
    android:drawable="@drawable/default_02_0035"
    android:duration="80"/>
         <item
    android:drawable="@drawable/default_02_0036"
    android:duration="80"/>
          <item
    android:drawable="@drawable/default_02_0037"
    android:duration="80"/>
           <item
    android:drawable="@drawable/default_02_0038"
    android:duration="80"/>
            <item
    android:drawable="@drawable/default_02_0039"
    android:duration="80"/>
             <item
    android:drawable="@drawable/default_02_0040"
    android:duration="80"/>
              <item
    android:drawable="@drawable/default_02_0041"
    android:duration="80"/>
               <item
    android:drawable="@drawable/default_02_0042"
    android:duration="80"/>
                <item
    android:drawable="@drawable/default_02_0043"
    android:duration="80"/>
                 <item
    android:drawable="@drawable/default_02_0044"
    android:duration="80"/>
                  <item
    android:drawable="@drawable/default_02_0045"
    android:duration="80"/>

</animation-list>

我使用AnimationDrawable制作逐帧动画。 当图像低于20pic时,应用程序工作正常,但在我在应用程序中添加更多图像后会崩溃。

任何可以分享一些教程如何制作动画可以加载更多图像? 我也用同样的方式购买2本书来逐帧制作动画。有什么好书吗?

THX

1 个答案:

答案 0 :(得分:0)

我猜这是某种类型的记忆限制她阻止你。说错误日志adb logcat有用吗?

您是否尝试过而不是同时加载所有内容,在需要时加载每一帧或在需要之前加载一下? 使用AnimationDrawable.addFrame添加动态新帧,但我不知道在显示下一帧时如何检测,但我想这可以做到。