画像がありません&ボタンのクリックイベントでこの画像を表示するにはフレームアニメーションを使用しましたが、最初にボタンをクリックすると画像がシーケンスで表示されます&このボタンをクリックすると画像が表示されない時間がもう1回あります。以下は私のコードです。Androidでボタンをクリックしたときのフレームアニメーション
Animation.javaファイル: -
public class Animation extends Activity {
Button mBtnOK;
AnimationDrawable frameAnimation;
ImageView imgView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBtnOK = (Button) findViewById(R.id.mBtnOK);
mBtnOK.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animate();
}
});
}
private void animate() {
imgView = (ImageView) findViewById(R.id.simple_anim);
imgView.setVisibility(ImageView.VISIBLE);
imgView.setBackgroundResource(R.anim.simple_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) imgView
.getBackground();
frameAnimation.start();
frameAnimation.setOneShot(true);
}
}
アニメーションファイル: -
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" id="selected" android:oneshot="false">
<item android:drawable="@drawable/monkey_1" android:duration="50" />
<item android:drawable="@drawable/monkey_2" android:duration="50" />
<item android:drawable="@drawable/monkey_3" android:duration="50" />
<item android:drawable="@drawable/monkey_4" android:duration="50" />
<item android:drawable="@drawable/monkey_5" android:duration="50" />
<item android:drawable="@drawable/monkey_6" android:duration="50" />
<item android:drawable="@drawable/monkey_7" android:duration="50" />
<item android:drawable="@drawable/monkey_8" android:duration="50" />
<item android:drawable="@drawable/monkey_9" android:duration="50" />
<item android:drawable="@drawable/monkey_10" android:duration="50" />
</animation-list>
frameAnimation.setVisible(true、true); frameAnimation.start();これを実行すると、アニメーションフレームが2回実行されます。 setVisible(true、true)だけが必要です。最初のtrueが表示され、2番目のtrueがアニメーションを最初の実行のように再起動します。 –