Android Question Animation End event not working when animation is inside a loop?

ncc1701mda

Member
Licensed User
Longtime User
For some reason in the attached code the animation end event is never called. Probably a stupid mistake, but can anyone tell me why in this case? Thanks in advance!

Mike
 

Emme Developer

Well-Known Member
Licensed User
Longtime User
You should also upload your layout file.
By the way, if i rightly remember, you can't use the same animation with more than one view at same time. You should declare a new animation object in loop and then start it, instead using only one
 
Upvote 0

ncc1701mda

Member
Licensed User
Longtime User
Sorry - didn't realize the export as zip didn't include it automatically. Revised Zip with main.bal file attached here.
 

Attachments

  • Animiation Loop Test.zip
    6.7 KB · Views: 335
Upvote 0

ncc1701mda

Member
Licensed User
Longtime User
That's odd... I am running this on an emulator - android version 4.2.2 - does the version of android make any difference?

Edit: I tried this on another version emulator - 7.1 - the animation end event is still never called when I step through.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sorry - didn't realize the export as zip didn't include it automatically.
It does. Make sure that the layout file is listed in the Files tab (click on the sync button).

Don't use the Animation library at all.

You can simplify your code with:
B4X:
For Each v As View In iv_P1_Card_1
   v.SetLayout(iv_Draw_Pile.Left - v.Left, iv_Draw_Pile.Top - v.Top, v.Width, v.Height)
   v.SetLayoutAnimated(500, 0, 0, v.Width, v.Height)
   Sleep(500) 'assuming that you want to animate then one after another
Next
 
Upvote 0

ncc1701mda

Member
Licensed User
Longtime User
Wouldn't this code move the view each time? What I am trying to do is leave the views where they are in the layout but show the card as moving from the draw pile to the card location. Not sure why the end event is not being activated.
 
Upvote 0

ncc1701mda

Member
Licensed User
Longtime User
Not sure why you think the code is incorrect... the logic flow seems to be right.

I determined that the AnimationEnd event doesn't seem to trigger when you single step through the code but if you run the code it works as expected (added a counter to see it).

My original thought was to use a boolean to check that the animation had ended before starting the next animation but when run that way no animation appeared to start and the program would hang in the loop waiting for the boolean to change (which it never did because the AnimationEnd event never happened). I also found that if a sleep is added afer the start of the animation but before the loop and the sleep is longer than the animation duration it works as expected. If the sleep is shorter than the animation it will not work - the animation will only progress part way and then again a hang in the loop waiting for the boolean to change. I fixed this by moving the sleep to inside the loop that checks the boolean and interestingly it doesn't matter how long the sleep is - even zero works.

Any thoughts on why this happens? Revised code attached.
 

Attachments

  • Animiation Loop Test.zip
    7.1 KB · Views: 330
Upvote 0

ncc1701mda

Member
Licensed User
Longtime User
Thanks for the clarification Erel. No need to debug the code - the last version I uploaded is working as expected.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…