Android 停止动画并重新开始
我想在ObjectAnimation运行时,单击动画图像视图时停止它。然后,我想在该ImageView上播放帧动画。之后,第一个动画再次开始 我的听众:Android 停止动画并重新开始,android,exception,animation,imageview,wait,Android,Exception,Animation,Imageview,Wait,我想在ObjectAnimation运行时,单击动画图像视图时停止它。然后,我想在该ImageView上播放帧动画。之后,第一个动画再次开始 我的听众: OnClickListener click = new OnClickListener() { @Override public void onClick(View arg0) { try { animator.w
OnClickListener click = new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
animator.wait(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setFrameAnimation(view);
}
};
view.setOnClickListener(click);
Animator是对象Animator动画。视图是我的图像视图 我的setFrameAnimation方法:
AnimationDrawable frameAnimation = (AnimationDrawable)view.Background();
frameAnimation.start();
这个代码不起作用。调用wait()时,我得到了非法的MonitorStateException.要使用“等待”,你需要在
同步的块中读取等待方法的文档。现在我没有得到异常,但我没有得到我的目标。要使用“等待”,你需要在同步的块中读取等待方法的文档。现在我没有得到异常,但我没有得到我的目标。这应该有什么帮助我我无法使用stop()停止ObjectAnimator。这对我有什么帮助?我无法使用stop()停止ObjectAnimator。
Use this
int duration = 150;
img = (ImageView)findViewById(R.id.imageView1);
BitmapDrawable frame1 =
(BitmapDrawable)getResources().getDrawable(R.drawable.y1);
BitmapDrawable frame2 =
(BitmapDrawable)getResources().getDrawable(R.drawable.y2);
BitmapDrawable frame3 =
(BitmapDrawable)getResources().getDrawable(R.drawable.y3);
BitmapDrawable frame4 =
(BitmapDrawable)getResources().getDrawable(R.drawable.y4);
BitmapDrawable frame5 =
(BitmapDrawable)getResources().getDrawable(R.drawable.y5);
animation = new AnimationDrawable();
animation.addFrame(frame1, duration);
animation.addFrame(frame2, duration);
animation.addFrame(frame3, duration);
animation.addFrame(frame4, duration);
animation.addFrame(frame5, duration);
// animation.addFrame(frame6, duration);
// animation.addFrame(frame7, duration);
// animation.addFrame(frame8, duration);
// animation.addFrame(frame9, duration);
// animation.addFrame(frame10, duration);
img.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
animation.setOneShot(false);
img.setBackgroundDrawable(animation);
animation.start();
}
});
btnStart = (Button)findViewById(R.id.btnStart);
btnStop = (Button)findViewById(R.id.btnStop);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animation.start();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animation.stop();
}
});