Android Question Rotate a image without repeat animation

Douglas Farias

Expert
Licensed User
Longtime User
Hi all
how can i rotate a image without animation when start again?

I need to make a circle like this
circle_img.png


Button to start rotate and a button to stop
i m tryed the animation lib
animation.InitializeRotateCenter("", 0, 180, imgview1)

this works but have a effect when stop and start again, like fade animation.
i need rotate my imageview for ever dont stop, only stop when i press a button

i m tryed
anima.InitializeRotateCenter("", 0, 360, imgventilador)
anima.RepeatCount = -1

but dont work too, i see a animation stop before start the repeate.

how can i spin the image for ever with velocity x?

thx all
 

eurojam

Well-Known Member
Licensed User
Longtime User
you can do it wth canvas and a timer...see attached example, it is b4j, but in b4a would be the same - the wheel is not that round, but that is a graphic problem...
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Canvas1 As Canvas
    Private Button1 As Button
    Private b As Image
    Private t As Timer
    Private angle As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
   
    b.Initialize(File.DirAssets, "circle_img.png")
   
    Canvas1.DrawImage(b,0,0,b.Width,b.Height) ',0,0,Canvas1.Width,Canvas1.height)
    t.Initialize("t",10)
    angle = 0
   
End Sub

Sub t_tick
    angle = angle + 1
    If angle = 360 Then angle=0
    Canvas1.DrawImageRotated(b,0,0,b.Width,b.Height, angle)
End Sub

Sub Button1_Action
    If t.Enabled Then
      t.Enabled=False
    Else 
      t.Enabled=True           
    End If
   
End Sub
 

Attachments

  • rotate.zip
    55.9 KB · Views: 427
Upvote 0
Top