2011-12-13 10 views

答えて

1

。すべての画像をドロウアブルフォルダに保存し、特定の時間の経過後にアニメーション化することができます。

abc1、abc2、abc3などの描画可能なフォルダに画像があるとします。それから、1つのImageViewを取り、そのImageViewのすべての画像をアニメーションを使って繰り返します。

このように試してみましょう。ここでは5つの画像しか考慮していないので、125のループがあれば、ループは125回まで移動するはずです。

私のxml - main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center_vertical|center_horizontal" 
    > 
<ImageView android:id="@+id/imgView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
</LinearLayout> 

私のJavaクラス - mainAct.java

public class mainAct extends Activity { 

    AnimationDrawable anim = new AnimationDrawable(); 
    Handler handler = new Handler(); 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     ImageView imageView = (ImageView) findViewById(R.id.imgView); 

     for (int i = 1; i <= 5; i++) { 
      anim.addFrame(getResources().getDrawable(getResources().getIdentifier("abc"+i, "drawable", getPackageName())), 1000); 
     } 

     imageView.setBackgroundDrawable(anim); 
     imageView.post(new Runnable() { 
      @Override 
      public void run() { 
       anim.start(); 
       handler.postDelayed(new Runnable() { 

        @Override 
        public void run() { 
         mainAct.this.finish(); 
        } 
       },getTotalAnimationDuration()); 
      } 
     }); 
    } 

    private int getTotalAnimationDuration() { 
     int mDuration = 0; 
     for (int i = 0; i < anim.getNumberOfFrames(); i++) { 
      mDuration = mDuration + anim.getDuration(i); 
     } 
     return mDuration; 
    } 

    @Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     anim.stop(); 
    } 
} 
+1

それは良い解決策だが、私はそれを試してみましたが、アプリケーションがあまりにも多くのスペースについての墜落がallocedされていること: 12-14 11:19:15.762:E/AndroidRuntime(14259):java.lang.OutOfMemoryError:ビットマップサイズがVMバジェットを超えています – max246

+0

エラーが発生したイメージの数がいくつですか? –

+0

30回後イメージ – max246

関連する問題