Android Code Snippet [B4X] [XUI] Simple Halo Animation

Code to create a nice halo animation:

halo.gif


Code is compatible with B4A, B4J and B4i.
B4X:
Sub CreateHaloEffect (Parent As B4XView, x As Int, y As Int, clr As Int)
   Dim cvs As B4XCanvas
   Dim p As B4XView = xui.CreatePanel("")
   Dim radius As Int = 150dip
   p.SetLayoutAnimated(0, 0, 0, radius * 2, radius * 2)
   cvs.Initialize(p)
   cvs.DrawCircle(cvs.TargetRect.CenterX, cvs.TargetRect.CenterY, cvs.TargetRect.Width / 2, clr, True, 0)
   Dim bmp As B4XBitmap = cvs.CreateBitmap
   For i = 1 To 5
     CreateHaloEffectHelper(Parent,bmp, x, y, clr, radius)
     Sleep(800)
   Next
End Sub

Sub CreateHaloEffectHelper (Parent As B4XView,bmp As B4XBitmap, x As Int, y As Int, clr As Int, radius As Int)
   Dim iv As ImageView
   iv.Initialize("")
   Dim p As B4XView = iv
   p.SetBitmap(bmp)
   Parent.AddView(p, x, y, 0, 0)
   Dim duration As Int = 3000
   p.SetLayoutAnimated(duration, x - radius, y - radius, 2 * radius, 2 * radius)
   p.SetVisibleAnimated(duration, False)
   Sleep(duration)
   p.RemoveViewFromParent
End Sub

Usage example:
B4X:
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
   If Action = Activity.ACTION_DOWN Then
     CreateHaloEffect(Activity, X, Y, xui.Color_Red)
   End If
End Sub

Requires XUI library v1.25+
 
Last edited:

Almora

Well-Known Member
Licensed User
Longtime User
hi..

I created a project but did not react at all. no error code.
XUI library v1.25+ ---->ok

B4X:
Sub Process_Globals
   
    Dim xui As XUI
End Sub

Sub Globals
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
 
     Activity.LoadLayout("d")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub CreateHaloEffect (Parent As B4XView, x As Int, y As Int, clr As Int)
    Dim cvs As B4XCanvas
    Dim p As B4XView = xui.CreatePanel("")
    Dim radius As Int = 150dip
    p.SetLayoutAnimated(0, 0, 0, radius * 2, radius * 2)
    cvs.Initialize(p)
    cvs.DrawCircle(cvs.TargetRect.CenterX, cvs.TargetRect.CenterY, cvs.TargetRect.Width / 2, clr, True, 0)
    Dim bmp As B4XBitmap = cvs.CreateBitmap
    For i = 1 To 5
        CreateHaloEffectHelper(Parent,bmp, x, y,  radius)
        Sleep(800)
    Next
End Sub

Sub CreateHaloEffectHelper (Parent As B4XView,bmp As B4XBitmap, x As Int, y As Int, radius As Int)
    Dim iv As ImageView
    iv.Initialize("")
    Dim p As B4XView = iv
    p.SetBitmap(bmp)
    Parent.AddView(p, x, y, 0, 0)
    Dim duration As Int = 3000
    p.SetLayoutAnimated(duration, x - radius, y - radius, 2 * radius, 2 * radius)
    p.SetVisibleAnimated(duration, False)
    Sleep(duration)
    p.RemoveViewFromParent
End Sub



Sub Activity_Touch (Action As Int, X As Float, Y As Float)
    If Action = Activity.ACTION_DOWN Then
        CreateHaloEffect(Activity, X, Y, xui.Color_Red)
    End If
End Sub
 

Almora

Well-Known Member
Licensed User
Longtime User
I have no events. may be related to the phone I use.
thanks..
 
Top