Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate image on center not going smooth (Monodroid)

I have an Image (which looks like a round loading circle) that I want to rotate around it's own center.. I saw a lot of code which suggested to set the PivotY and PivotX to 0.5F or th half of the image. Both does not work.. After a lot of trial and error it does rotate around it's own center with the following code:

ImageView loading = FindViewById<ImageView>(Resource.Id.loadingGif);
RotateAnimation rAnim = new RotateAnimation(0.0F, 359.0F,      Dimension.RelativeToSelf, 0.25F, Dimension.RelativeToSelf, 0.25F);
rAnim.Interpolator = new LinearInterpolator();
rAnim.RepeatCount = Animation.Infinite;
rAnim.Duration = 1000;
loading.StartAnimation(rAnim);

But the animation itself is not going smooth anymore, the image seems to rotate about 50degrees then starts to hang and skips half of the rotation and then continues normally on the top half of the rotation (I hope that makes any sense).

Any idea why my rotation does not rotate the full 360 degrees smoothly?

EDIT

I still haven't solved this problem, but I did just discover something peculiar about it. The animation is used on a loading screen with no extra functionalities on the moment of the animation. I noticed that when I keep my finger on the screen the animation DOES happen smoothly!!

This got me thinking that the issue maybe isn't in the animation code but something else.. but what I don't know yet..

like image 778
Lieketjj Avatar asked Sep 06 '12 08:09

Lieketjj


1 Answers

I've finally found the answer!

I've included the line:

loading.setDrawingCacheEnabled(true);

And after that had to change the pivots to 0.5F too. And now the animation runs smoothly!

//Rotate image
ImageView loading = FindViewById<ImageView>(Resource.Id.loadingGif);
loading.setDrawingCacheEnabled(true);
rAnim = new RotateAnimation(0.0F, 359.0F, Dimension.RelativeToSelf, 0.5F, Dimension.RelativeToSelf, 0.5F);  
rAnim.Interpolator = new LinearInterpolator();
rAnim.RepeatCount = Animation.Infinite;
rAnim.Duration = 1500;
loading.StartAnimation(rAnim);
like image 54
Lieketjj Avatar answered Oct 12 '22 11:10

Lieketjj