Android Code Snippet Animation with SetLayoutAnimated

Discussion in 'Code Snippets' started by rraswisak, Jul 20, 2019.

  1. rraswisak

    rraswisak Member Licensed User

    Hi all,

    I'm on create a simple app which use the power of SetLayoutAnimated method for doing animation. I know every one can do better than this but i want to share in case it is useful for community.

    Basic idea is moving (any) views from one coordinate to another, in this example i only move Label view (with image drawable) who has Tag property value is not empty, so here we go...

    Code:
    Sub DoAnimation
       
    Dim mOrigPos As Map
       mOrigPos.Initialize

       
    For Each v As View In Activity.GetAllViewsRecursive
           
    If v Is Label And v.Tag <> "" Then
               mOrigPos.Put(v.Tag, 
    Array As Int (v.Left, v.Top, v.Width, v.Height))
               
    Select Rnd(1,8)
                   
    Case 1
                       
    'top-left
                       v.Top = v.Height * -1
                       v.Left = v.Width * -
    1
                   
    Case 2
                       
    'top
                       v.Top = v.Height * -1
                       v.Left = (
    100%x - v.Width) / 2
                   
    Case 3
                       
    'top-right
                       v.Top = v.Height * -1
                       v.Left = 
    100%x
                   
    Case 4
                       
    'right
                       v.Top = (100%y - v.Height) / 2
                       v.Left = 
    100%x
                   
    Case 5
                       
    'bottom-right
                       v.Top = 100%y
                       v.Left = 
    100%x
                   
    Case 6
                       
    'bottom
                       v.Top = 100%y
                       v.Left = (
    100%x - v.Width) / 2
                   
    Case 7
                       
    'bottom-left
                       v.Top = 100%y
                       v.Left = v.Width * -
    1
                   
    Case 8
                       
    'left
                       v.Top = (100%y - v.Height) / 2
                       v.Left = v.Width * -
    1
               
    End Select
           
    End If
       
    Next

       
    Dim pos() As Int
       
    For Each v As View In Activity.GetAllViewsRecursive
           
    If v Is Label And v.Tag <> "" Then
               pos = mOrigPos.Get(v.Tag)
               v.SetLayoutAnimated(
    1000, pos(0), pos(1), pos(2), pos(3))
               Sleep(
    0)
           
    End If
       
    Next
       Main.onAnim = 
    False
    End Sub
    Here is the result:

    5d3331429fbfe377109009.gif
     
    Livio F, AnandGupta, Erel and 6 others like this.
  2. LucaMs

    LucaMs Expert Licensed User

    Really a strange choice :)
     
  3. rraswisak

    rraswisak Member Licensed User

    @LucaMs, trying to be different and out of the generalism ;)
     
    LucaMs likes this.
Loading...
  1. 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.
    Dismiss Notice