我正在尝试在我正在为课堂设计的应用程序中拥有帧动画但是应用程序仍在崩溃,尽管我已经完成了关于如何进行帧动画的研究。是否更有可能是我的android工作室烦恼或代码不正确?
<item android:drawable="@drawable/archerclip1" android:duration="100"/>
<item android:drawable="@drawable/archerclip2" android:duration="100"/>
<item android:drawable="@drawable/archerclip3" android:duration="100"/>
<item android:drawable="@drawable/archerclip4" android:duration="100"/>
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FrameAnimation extends Activity {
AnimationDrawable archerAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame_animation);
Button btnStart = (Button)findViewById(R.id.btnStart);
Button btnStop = (Button)findViewById(R.id.btnStop);
ImageView imgFrameAnimation = (ImageView)findViewById(R.id.imgFrameAnimation);
imgFrameAnimation.setBackgroundResource(R.drawable.animationone);
archerAnimation = (AnimationDrawable)imgFrameAnimation.getBackground();
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
archerAnimation.start();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
archerAnimation.stop();
}
});
}
}
java.lang.OutOfMemoryError: Failed to allocate a 20232732 byte allocation with 4194304 free bytes and 17MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1080)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2635)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:324)
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:294)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1215)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1124)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2630)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.Resources.getDrawable(Resources.java:806)
at android.content.Context.getDrawable(Context.java:458)
at android.view.View.setBackgroundResource(View.java:17202)
at edu.wmich.lab5rfoste1057.FrameAnimation.onCreate(FrameAnimation.java:23)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:0)
ImageView imgFrameAnimation = (ImageView)findViewById(R.id.imgFrameAnimation);
您在此处设置的图片非常大。尝试将其调整为更小的尺寸。