我的 xml 文件中有一个 ImageView,我想在单击时旋转图像。
我使用以下代码存档:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
img = (ImageView) findViewById(R.id.imageView1);
Animation an = new RotateAnimation(0.0f, 360.0f, img.getWidth() / 2,
img.getHeight() / 2);
an.reset();
// Set the animation's parameters
an.setDuration(1000); // duration in ms
an.setRepeatCount(0); // -1 = infinite repeated
an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
//an.start();
img.setAnimation(an);
}
return true;
}
但问题是,当我按下图像时,没有任何反应,图像不会转动。但是,如果我单击图像,然后单击 TextView,图像会旋转。
这太随意了。
我究竟做错了什么?我怎样才能解决这个问题?
谢谢。