我的应用程序中有一个图像...当我单击开始按钮时,图像需要旋转..当我单击停止按钮时,图像设置为原始位置...相反,我希望图像准确地停止位置..这是我的代码
public class MainActivity extends Activity {
ImageView my_image;
AnimationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listener = new AnimationListener() {
@Override public void onAnimationStart(Animation animation) {}
@Override public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
System.out.println("End Animation!");
//load_animations();
}
};
my_image=(ImageView)findViewById(R.id.imageView1);
load_animations();
Button start=(Button)findViewById(R.id.button1);
Button stop=(Button)findViewById(R.id.button2);
}
void load_animations()
{
Button start=(Button)findViewById(R.id.button1);
Button stop=(Button)findViewById(R.id.button2);
new AnimationUtils();
final Animation rotation = AnimationUtils.loadAnimation(this, R.anim.animation);
rotation.setAnimationListener(listener);
start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
my_image.startAnimation(rotation);
}
});
stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
my_image.clearAnimation();
}
});
}
}