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!
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
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
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.
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.
You cannot hold the main thread in a loop without using Sleep. I haven't debugged your code, as I previously wrote you can simplify it by using SetLayoutAnimated with Sleep.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.