Android 逐帧动画中java.lang.OutOfMemoryError:位图大小超出VM预算
我尝试在单击按钮时加载动画。我在resources文件夹中有90个图像,我尝试加载它们,每个图像的大小约为50kb,当我单击“开始动画”按钮时,我发现异常,因为内存不足。请检查以下代码。任何帮助都将不胜感激Android 逐帧动画中java.lang.OutOfMemoryError:位图大小超出VM预算,android,animation,memory-leaks,Android,Animation,Memory Leaks,我尝试在单击按钮时加载动画。我在resources文件夹中有90个图像,我尝试加载它们,每个图像的大小约为50kb,当我单击“开始动画”按钮时,我发现异常,因为内存不足。请检查以下代码。任何帮助都将不胜感激 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); startbtn=(Butt
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startbtn=(Button) findViewById(R.id.myStartButton);
stopbtn=(Button)findViewById(R.id.myStopButton);
startbtn.setOnClickListener(this);
stopbtn.setOnClickListener(this);
images=(ImageView) findViewById(R.id.myImageView);
images.setBackgroundResource(R.drawable.demo_animation);
AniFrame = (AnimationDrawable)images.getBackground();
}
public void onClick(View v) {
if(v.getId()==R.id.myStartButton)
{
AniFrame.start();
}else if(v.getId()==R.id.myStopButton)
{
AniFrame.stop();
}
}
图像是否经过压缩(jpg或png)?我认为当它们被加载到内存中时,它们会被转换成位图格式,并使用更多的内存(每像素最多4个字节)。
这可能是导致outofmemoryexception的原因。您无法计算磁盘上的90x50kb,请以90x750KB为单位。查看页面右侧的“相关”问题。你会发现这个问题已经被完全忽略了。我看到了相关的问题,但没有得到正确的解决方案。