我的問題是我有一些圖片&我用框架動畫來顯示這個圖像點擊事件的按鈕,但如果我點擊按鈕第一次圖像順序顯示&如果我點擊此按鈕另一次該圖像不顯示。以下是我的代碼。框架動畫按鈕點擊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();運行這將導致幀Animation運行兩次。您只需要setVisible(true,true):第一個true set可見,第二個true將重新啓動動畫,就像它是第一次運行一樣。 – 2012-08-19 03:13:26