いつもお世話になっております。質問させて頂きます。
現在、時間経過とともに画像アニメーションが変化するアプリを開発しています。
Java
1 customAnimationDrawableNew = new CustomAnimationDrawableNew( 2 (AnimationDrawable) getResources().getDrawable( 3 R.drawable.seventh_phase)) { 4 @Override 5 void onAnimationFinish() { 6 // Animation has finished... 7 } 8 }; 9 10 // Set the views drawable to our custom drawable 11 plantImageView.setBackgroundDrawable(customAnimationDrawableNew); 12 13 new Thread(new Runnable(){ 14 @Override 15 public void run() { 16 handler.post(new Runnable() { 17 public void run() { 18 customAnimationDrawableNew.start(); 19 } 20 }); 21 } 22 }).start();
Java
1public abstract class CustomAnimationDrawableNew extends AnimationDrawable { 2 3 /** Handles the animation callback. */ 4 Handler mAnimationHandler; 5 6 public CustomAnimationDrawableNew(AnimationDrawable aniDrawable) { 7 /* Add each frame to our animation drawable */ 8 for (int i = 0; i < aniDrawable.getNumberOfFrames(); i++) { 9 this.addFrame(aniDrawable.getFrame(i), aniDrawable.getDuration(i)); 10 } 11 } 12 13 @Override 14 public void start() { 15 super.start(); 16 /* 17 * Call super.start() to call the base class start animation method. 18 * Then add a handler to call onAnimationFinish() when the total 19 * duration for the animation has passed 20 */ 21 mAnimationHandler = new Handler(); 22 mAnimationHandler.postDelayed(new Runnable() { 23 24 public void run() { 25 onAnimationFinish(); 26 } 27 }, getTotalDuration()); 28 29 } 30 31 /** 32 * Gets the total duration of all frames. 33 * 34 * @return The total duration. 35 */ 36 public int getTotalDuration() { 37 38 int iDuration = 0; 39 40 for (int i = 0; i < this.getNumberOfFrames(); i++) { 41 iDuration += this.getDuration(i); 42 } 43 44 return iDuration; 45 } 46 47 /** 48 * Called when the animation finishes. 49 */ 50 abstract void onAnimationFinish(); 51}
基本的には上記のコードで時間が経過したら、下記コード
Java
1 customAnimationDrawableNew = new CustomAnimationDrawableNew( 2 (AnimationDrawable) getResources().getDrawable( 3 R.drawable.seventh_phase)) { 4 @Override 5 void onAnimationFinish() { 6 // Animation has finished... 7 } 8 };
のgetDrawableのファイルを切りかえていきます。
継続してアプリを動かしていると、
08-29 11:20:25.549 5463-5463/com.radineer.fmn D/dalvikvm: GC_FOR_ALLOC freed 7799K, 20% free 48684K/60264K, paused 17ms, total 17ms
08-29 11:20:25.579 5463-5463/com.radineer.fmn I/dalvikvm-heap: Grow heap (frag case) to 69.049MB for 22380560-byte allocation
08-29 11:20:25.589 5463-5472/com.radineer.fmn D/dalvikvm: GC_FOR_ALLOC freed 3K, 15% free 70537K/82124K, paused 17ms, total 17ms
のようなエラーがでてしまし、アプリが固まってしまいます。いろいろ検索をして
android:largeHeap="true" android:supportsRtl="true"
上記のような設定は行っているのですが、、、、
何か改善策をご教示頂ければ幸いです。
何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/13 01:20