【问题标题】:Out of Memory error when using AnimationDrawable使用 AnimationDrawable 时出现内存不足错误
【发布时间】:2019-05-14 22:40:06
【问题描述】:

您好,我正在尝试从几个 png 图像创建徽标动画,我创建了一个动画,但它因内存不足错误而崩溃。有谁知道这个问题的解决方案吗?

这是我目前所拥有的

这是我的动画列表

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:drawable="@drawable/intro_animation_00" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_01" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_02" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_03" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_04" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_05" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_06" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_07" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_08" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_09" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_10" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_11" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_12" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_13" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_14" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_15" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_16" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_17" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_18" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_19" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_20" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_21" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_22" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_23" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_24" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_25" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_26" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_27" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_28" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_29" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_30" android:duration="50" />
</animation-list>

这是我的布局

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/bg"
    tools:context=".MenuActivity" >

        <ImageView
            android:id="@+id/myanimation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@anim/intro_animation"
        />

</RelativeLayout>

这是我的活动

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_menu);
        ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
        final AnimationDrawable myAnimationDrawable
        = (AnimationDrawable)myAnimation.getDrawable();

        myAnimation.post(
        new Runnable(){

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

    }

【问题讨论】:

  • 在模拟器中增加堆内存大小..
  • 我使用的设备不是模拟器

标签: android animation


【解决方案1】:

尝试在您的应用程序标签中添加largeHeap=true
显现。

我希望这会有所帮助。

或尝试使用小尺寸图片。

【讨论】:

  • 谢谢,这行得通。几乎感觉太容易了......只是读到这种方法的影响是增加了垃圾收集所花费的时间以及其他应用程序可能存在内存问题的可能性(我想是在各个应用程序的恢复时)
  • 这是一个临时解决方案
猜你喜欢
  • 2016-10-10
  • 1970-01-01
  • 2012-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 2011-04-18
  • 2016-01-09
相关资源
最近更新 更多