我想按播放按钮,然后旋转光盘:imageRound
。暂停时我想将光盘停止在当前位置,然后在播放时从当前位置继续。
我每次都尝试使用 imageRound.getRotation() 获取角度,但每次都会返回到 0。我的代码如下:
playButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (playShow) {
playButton.setBackgroundResource(R.drawable.play_pressed);
} else {
playButton.setBackgroundResource(R.drawable.pause_pressed);}
return true; //handle the touch event
case MotionEvent.ACTION_UP:
if (playShow) {
playButton.setBackgroundResource(R.drawable.pause_default);
RotateAnimation rotate = new RotateAnimation(imageRound.getRotation(), 360, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(5000);
imageRound.startAnimation(rotate);
playShow=false;
} else {
playButton.setBackgroundResource(R.drawable.play_default);
imageRound.setRotation(imageRound.getRotation()); //(Not working) Set angle and stop animation
imageRound.clearAnimation();
playShow=true;
}
return true; // handle the touch event
}
return false;
}
});
最佳答案
imageRound.getRotation()
每次都返回0吗? RotateAnimation 不会更改 View 的属性。使用 ObjectAnimator.ofFloat(imageview ,"rotation", 0f, 360f)
这会直接更改 View 的旋转属性。
关于java - 如何使用按钮启动和停止旋转 ImageView 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55323419/