2016-04-20 179 views
0

我正在嘗試在我正在設計的應用程序中使用框架動畫,但應用程序不斷崩潰,儘管我已經完成了關於框架動畫的研究。它更可能是我的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

添加了崩潰日誌 –

回答

0
ImageView imgFrameAnimation = (ImageView)findViewById(R.id.imgFrameAnimation); 

你在這裏設置的圖像是非常大的。嘗試調整它的大小。