在阅读了 stackoverflow 站点中的一些帖子后,我尝试使用 Frame 动画来构建动画
private void startAnimation(){
fireAnimation = new AnimationDrawable();
fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire1), 100);
fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire2), 100);
fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire3), 100);
fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire4), 100);
...
fireAnimation.addFrame(getResources().getDrawable(R.drawable.fire16), 100);
}
然后在 onCreate() 我做 startActivity();
But I have an error
02-12 13:31:31.909: E/dalvikvm-heap(4902): 1535664-byte external allocation too large for this process.
02-12 13:31:31.909: E/GraphicsJNI(4902): VM won't let us allocate 1535664 bytes
02-12 13:31:31.939: W/dalvikvm(4902): threadid=1: thread exiting with uncaught exception (group=0x40018560)
02-12 13:31:31.959: E/AndroidRuntime(4902): FATAL EXCEPTION: main
02-12 13:31:31.959: E/AndroidRuntime(4902): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.content.res.Resources.getDrawable(Resources.java:581)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.example.kersplatt.GameActivity.startAnimation(GameActivity.java:244)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.example.kersplatt.GameActivity.access$0(GameActivity.java:237)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.example.kersplatt.GameActivity$1.onTouch(GameActivity.java:80)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.View.dispatchTouchEvent(View.java:3881)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1738)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1127)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1722)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2196)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.view.ViewRoot.handleMessage(ViewRoot.java:1880)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.os.Looper.loop(Looper.java:130)
02-12 13:31:31.959: E/AndroidRuntime(4902): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-12 13:31:31.959: E/AndroidRuntime(4902): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 13:31:31.959: E/AndroidRuntime(4902): at java.lang.reflect.Method.invoke(Method.java:507)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
02-12 13:31:31.959: E/AndroidRuntime(4902): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
02-12 13:31:31.959: E/AndroidRuntime(4902): at dalvik.system.NativeStart.main(Native Method)
我有 16 张图片,当我只放 4 张时它可以工作。我能做些什么来减轻图像的重量?我应该减小尺寸 (600*650)m 什么才足以拥有良好的品质?