2016-01-20 63 views
-2

我有一个imageview图层,我想要将它旋转一下并停下来,当我再次触摸时,我该怎么办?Android - 如何在图像上旋转图像查看

+0

同样的问题被回答在这里 - http://stackoverflow.com/questions/8981845/android-rotate-image-in-imageview-by-an-angle –

回答

1

动画 DIR

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false"> 
    <rotate 
     android:duration="2500" 
     android:interpolator="@android:anim/linear_interpolator" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:repeatCount="infinite" 
     android:repeatMode="restart" 
     android:toDegrees="360" /> 
</set> 

现在,在你的类文件加载动画

Animation animation = AnimationUtils.loadAnimation(getContext(),R.anim.rotate); 

而且对你的形象点击开始动画创建动画rotate.xml

your_image.startAnimation(animation); 
+0

感谢和最后一个问题如果我再次触摸需要停止动画的图像,我该如何处理? – kingmaker

+0

采取一个布尔isAnimationRunning,并在动画开始时将其设置为true,反之亦然。如果没有运行,则只需单击图像即可开始动画。 –

0

您可以尝试以编程方式设置动画这样的:

RotateAnimation rotate = new RotateAnimation(0, 360, 
    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 
    0.5f); 

    rotate.setDuration(4000); 
    rotate.setRepeatCount(Animation.INFINITE); 
    yourView.setAnimation(rotate); 

希望它能帮助。

+0

如何做ontouch旋转和ontouch再次停止旋转? – kingmaker