Android Question How use SetRotationAnimated again?

Douglas Farias

Expert
Licensed User
Longtime User
Hi all.
i m using this sub into a class module.

B4X:
Sub Animacao_Rotacao (v As B4XView, duracao As Int, volta As Int)
    If v.IsInitialized And v.Rotation <> 0 Then Return
    If v.IsInitialized Then v.SetRotationAnimated(duracao, volta)
    Sleep(duracao)
    If v.IsInitialized Then v.Rotation = 0
    Sleep(10)
End Sub

it is a simple animation to rotate the view, a imageview.
i call this sub on the click of imageview

B4X:
geral.Animacao_Rotacao(imgLogoMenu,500,360)

now the question is, why this code works only the first time? on the first click?

i set it to rotate 360 right? later i set to 0 again to restart, thats correct?
how can i make to rotate when i click on the view? every time.

thx
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why do you need to check whether v is initialized? If it is not initialized then there is a programming error which should be fixed.

Change your code to:
B4X:
Sub Animacao_Rotacao (v As B4XView, duracao As Int, volta As Int)
   v.SetRotationAnimated(duracao, volta)
   Sleep(duracao + 20) '+20 to make sure that the new value is set after animation completes.
   v.Rotation = 0
End Sub
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
Hi erel.
its because this sub is under a class, and i have a lot of activitys, where can i close the current activity (view removed) and the sub will continue because the sleep.

thx for the example
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…