我有一个图像,我只是试图旋转它(旋转360)几次围绕其中心。然而,我的尝试只是导致图像形成一个很宽的圆圈——我认为是在包含视图的左上角。
我发现这个如何旋转一个android图标在其中心点?这看起来非常相似,但是如何在XML动画定义中做到这一点呢?
My animation XML:
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1600"
android:repeatCount="infinite"
/>
为什么不使用图像作为进度条呢?它会旋转中心的次数,直到你解散它。
试试这个代码
ImageView diskView = (ImageView) findViewById(R.id.imageView3);
// Create an animation instance
Animation an = new RotateAnimation(0.0f, 360.0f, pivotX, pivotY);
// Set the animation's parameters
an.setDuration(10000); // duration in ms
an.setRepeatCount(0); // -1 = infinite repeated
an.setRepeatMode(Animation.REVERSE); // reverses each repeat
an.setFillAfter(true); // keep rotation after animation
// Apply animation to image view
diskView.setAnimation(an);