The layout should be made of a "base panel" that holds all other views.
The base panel is then replaced with an ImageView and returned back at the end of the animation.
'Type in globals: Type PixelGroup (SrcX As Int, SrcY As Int, x As Float, y As Float, dx As Float, dy As Float) Sub ImplodeLayout(BasePanel As B4XView, NumberOfSteps As Int) As ResumableSub #if debug Log("Animation disabled in debug mode.") Sleep(0) Return True #End If Dim scale As Float = 100dip / 100 Dim bc As BitmapCreator Dim GroupSize As Int = 6 'you can play with this size to change the effect. Dim iv As ImageView iv.Initialize("") Dim xiv As B4XView = iv Dim bmp As B4XBitmap = BasePanel.Snapshot BasePanel.Parent.AddView(xiv, BasePanel.Left, BasePanel.Top, BasePanel.Width, BasePanel.Height) BasePanel.RemoveViewFromParent Dim w As Int = xiv.Width / scale / GroupSize Dim h As Int = xiv.Height / scale / GroupSize bc.Initialize(w * GroupSize, h * GroupSize) Dim source As BitmapCreator source.Initialize(bc.mWidth, bc.mHeight) source.CopyPixelsFromBitmap(bmp) Dim steps As Int = NumberOfSteps Dim pgs(w, h) As PixelGroup For x = 0 To w - 1 For y = 0 To h - 1 Dim pg As PixelGroup = pgs(x, y) pg.SrcX = x * GroupSize pg.Srcy = y * GroupSize Select Rnd(0, 4) Case 0 pg.x = 0 pg.y = Rnd(0, bc.mHeight) Case 1 pg.x = bc.mWidth - 1 pg.y = Rnd(0, bc.mHeight) Case 2 pg.x = Rnd(0, bc.mWidth) pg.y = 0 Case 3 pg.x = Rnd(0, bc.mWidth) pg.y = bc.mHeight - 1 End Select pg.dx = (pg.SrcX - pg.x) / steps pg.dy = (pg.SrcY - pg.y) / steps Next Next Dim r As B4XRect r.Initialize(0, 0, 0, 0) For i = 0 To steps - 1 bc.FillRect(xui.Color_Transparent, bc.TargetRect) For x = 0 To w - 1 For y = 0 To h - 1 Dim pg As PixelGroup = pgs(x, y) pg.x = pg.x + pg.dx pg.y = pg.y + pg.dy r.Left = pg.SrcX r.Right = pg.SrcX + GroupSize r.Top = pg.SrcY r.Bottom = pg.SrcY + GroupSize bc.DrawBitmapCreator(source, r, pg.x, pg.y, True) Next Next xiv.SetBitmap(bc.Bitmap) Sleep(16) Next xiv.Parent.AddView(BasePanel, xiv.Left, xiv.Top, xiv.Width, xiv.Height) xiv.RemoveViewFromParent Return True End Sub
Tested in B4J. Should also work in B4A and B4i.
23 KB Views: 315