Android Example [B4X] Like Animation - smooth and beautiful transition

This is a simple like animation.
It looks smoother and better in real.
ezgif.com-video-to-gif.gif

LikeAnimation:
Private Sub LikeAnimation(xlbl As B4XView,duration As Int)
    Dim txt_size As Float = xlbl.TextSize
    If xlbl.Text = Chr(0xE87E) Then
        xlbl.SetTextSizeAnimated(duration/2,1)
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87D)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    Else
        xlbl.SetTextSizeAnimated(duration/2,1)
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87E)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    End If
End Sub
LikeAnimationColored:
Private Sub LikeAnimationColored(xlbl As B4XView,duration As Int,liked_color As Int,unliked_color As Int)
    Dim txt_size As Float = xlbl.TextSize
    If xlbl.Text = Chr(0xE87E) Then
        xlbl.SetTextSizeAnimated(duration/2,1)
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87D)
        xlbl.TextColor = liked_color
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    Else
        xlbl.SetTextSizeAnimated(duration/2,1)
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87E)
        xlbl.TextColor = unliked_color
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    End If
End Sub
 

Attachments

  • Like Animation.zip
    9.8 KB · Views: 526
Last edited:

TILogistic

Expert
Licensed User
Longtime User
some more animation:
B4X:
Private Sub LikeAnimation(xlbl As B4XView,duration As Int)
    Dim txt_size As Float = xlbl.TextSize
    If xlbl.Text = Chr(0xE87E) Then
        xlbl.SetTextSizeAnimated(duration/2,1)
        xlbl.SetRotationAnimated(duration,360) '--> Rotation
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87D)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    Else
        xlbl.SetTextSizeAnimated(duration/2,1)
        xlbl.SetRotationAnimated(duration,-360) '--> Rotation
        Sleep(duration/2)
        xlbl.Text = Chr(0xE87E)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    End If
End Sub
 

TILogistic

Expert
Licensed User
Longtime User
I wanted to say this:
LikeAnimation(xlbl_like,350)

B4X:
Private Sub LikeAnimation(xlbl As B4XView,duration As Int)
    Dim txt_size As Float = xlbl.TextSize
    If xlbl.Text = Chr(0xE87E) Then
        xlbl.SetRotationAnimated(duration*4,360) '--> Rotation
        xlbl.SetTextSizeAnimated(duration/2,txt_size/2)
        Sleep(duration)
        xlbl.Text = Chr(0xE87D)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    Else
        xlbl.SetRotationAnimated(duration*4,-360) '--> RotationY
        xlbl.SetTextSizeAnimated(duration/2,txt_size/2)
        Sleep(duration)
        xlbl.Text = Chr(0xE87E)
        xlbl.SetTextSizeAnimated(duration/2,txt_size)
    End If
End Sub
 
Top