Android Question How to cancel a view's animation?

JohnC

Expert
Licensed User
Longtime User
I am animating a panel's visibility using:
B4X:
Panel.SetVisibleAnimated(TimeinMs, False)
If I set the animation to a long duration, like 10 seconds, but then want to cancel the duration and set a new duration, it appears the original time duration will still execute.

For example, lets say I initially set the visibility to "False" (hide) the panel over a period of 10 seconds, then 5 seconds into the hide animation, I call the same animation with a new value of 20 seconds, the panel will still disappear at the original 10 second animation point.

How can I change the animation time without the original one be executed?

I tried these variations, but they did not work:
B4X:
Panel.SetVisibleAnimated(0, False)
Panel.visible = true
Panel.SetVisibleAnimated(20000, False)

Panel.visible = false
Panel.visible = true
Panel.SetVisibleAnimated(20000, False)
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

JohnC

Expert
Licensed User
Longtime User
That post might be related to my issue, but I need to use a panel for this particular app.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Class_Globals:
Private TimeinMs As Int = 3000
Private mStop As Boolean
B4X:
Private Sub Button1_Click
    If mStop Then
        Panel1.As(B4XView).SetVisibleAnimated(0, True)
    Else
        Panel1.As(B4XView).SetVisibleAnimated(TimeinMs, False)
    End If
    mStop = Not(mStop)
End Sub
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hi @LucaMs, thanks for the code, but I tried setting the duration to 0, but it still did not cancel the hide animation.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I ended up doing a brute-force solution to this issue...I destroy and recreate the panel whenever I need to change the animation time - mid animation.

It's ugly, but works.
 
Upvote 0
Top