Android Question How to animate Label to move from Down to Up slowly

ronovar

Active Member
Licensed User
Longtime User
I ned to animate Label that move text from bottom to top...i have one apk that have epg description label...and would like to implement feauture when user scrolls channel that label descritpion is visible only two rows after one second it move slowly text to up from down so that whole description label can be read.

How can i do this with label animation in b4a?

Thanks.

I try with this but label goes on top and whole panel is filled with whole label height...

B4X:
lblEPGDesc.SetLayoutAnimated(2000, 150dip, -10dip, 250dip, 76dip)
 

ronovar

Active Member
Licensed User
Longtime User
I have one string for example:

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

and in epg only first three rows are showed: so it is showed:

Lorem Ipsum is simply
dummy text of the printing and
typesetting industry.

and when moving up it needs to be when moving up this:

dummy text of the printing and
typesetting industry.
Lorem Ipsum has been the

and then:

typesetting industry.
Lorem Ipsum has been the
industry's standard dummy

and so on..i try this code but i think i need sub where string is cut and added at botoom:

B4X:
For I=0 To 50
    lblEPGDesc.SetLayoutAnimated(0, 150dip, 91dip - I, 250dip, 250dip)
    Delay(100)
Next

This works excellent...50 number is for try this code..i need to get using string utils length and now i need to figure out how to cut and insert above string like in above example
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Try this .. you should be able to adapt it to your needs ... ( include Animation lib)
B4X:
Sub Globals
   Private a As Animation
   Private Label1 As Label
   Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   Panel1.Initialize("")
   Activity.AddView(Panel1,50dip,50dip,600dip,100dip)
   
   Label1.Initialize("")
   Label1.Color = Colors.White
   Label1.TextColor = Colors.Black
   Label1.TextSize = 26
   Panel1.AddView(Label1,0,0,600dip,400dip)

   For i = 0 To 12
     Label1.Text = Label1.Text  & "And The Best Movie Award goes to  ...  Line  #  " & i & CRLF
   Next
   
   a.InitializeTranslate("Animation",0,0,0,-Label1.Height + 100dip)
   a.Duration=9000
   a.start(Label1)

End Sub

Sub Animation_AnimationEnd

   Label1.Text = " The End ..."

End Sub
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Had nothing to do ... so continued to played with your sample string . There might be more elegant way of splitting / joining the strings .
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Panel1.Initialize("")
   Activity.AddView(Panel1,50dip,50dip,600dip,100dip)

   Label1.Initialize("")
   Label1.Color = Colors.White
   Label1.TextColor = Colors.Black
   Label1.TextSize = 30
   Panel1.AddView(Label1,0,0,600dip,400dip)

   Dim myText As String
   myText =  $"Lorem Ipsum is simply dummy text of the printing and typesetting industry.
   Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer
   took a galley of type and scrambled it to make a type specimen book."$

   Dim tempStr()As String
   Dim newStr As String

   tempStr = Regex.Split("\s", myText)

   Dim nstart As Int = 0
   Dim nwords As Int = 6 'words per line  Note .. This should be a 'string size / length' factor

   Dim lst As List
   lst.Initialize

   Do While nstart < tempStr.Length

     For i = nstart To nstart + nwords     'build new sentence
       newStr = newStr & " " & tempStr(i)
     Next

     lst.Add(newStr)     'add sentence to list
     nstart = i

     If i + nwords > tempStr.Length - 1 Then     'set next loop size and adjust if needed
      nwords = (tempStr.Length -1) - i
     End If

     newStr = ""   'reset sentence

   Loop

   'display
   For i = 0 To lst.Size -1
     Label1.Text = Label1.Text &  lst.Get(i) & CRLF
   Next

   a.InitializeTranslate("Animation",0,0,0,-Label1.Height + 180dip)
   a.Duration= 8000  'This could be calculation  n * lst.Size ?
   a.start(Label1)

End Sub

Sub Animation_AnimationEnd

   Label1.Text = " The End ..."

End Sub[code]
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I im using this code:

B4X:
a.InitializeTranslate("Animation",0,0,0,-Label1.Height + 100dip)
 a.Duration=9000
 a.start(Label1)

And animation label1 text begins, when i scroll using customlistview down or up i need to stop previus animation and begin current selected animation to animate down.

I have try using:

B4X:
a.Stop("a")

But apk crash. How can i do to stop previus Label1.Text and Animate new selected panel Label1.Text?
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I fixed it by calling it correct:

B4X:
a.Stop("lblEPGs")

Another question is how to set visibility of CustomListView1 to false and true so that i can hide and show when needed.

I try pnlMaster.Visibily = False but panel in customlistview is showed[/CODE]
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Animation library have problems...that on scolled item it scrolls fast...so that i can't read text...on second scroll it scrolls normally, on third scrolls it scrolls slow...and so in loop so i put idea to move label slowly up by using timer...i write this code using timer..but problem is that label move nice up (every 200ms) up and then stops...in log i see that variable I is incrementing but label is not moving up or down...why?

here is code:

B4X:
Dim tmrEpgDesc As Timer

tmrEpgDesc.Initialize("tmrEpgDesc", 200)
tmrEpgDesc.Enabled = True

Sub tmrEpgDesc_Tick
    Log(I)
    lblEPGDesc.SetLayoutAnimated(0, 0, 90dip - I, 250dip, 250dip)
    'lblEPGDesc.Top = I <-- i try this but i commented it but it works as SetLayoutAnimated
     I = I + 1
     tmrEpgDesc.Enabled = True
End Sub
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Can you please give me example code? I im not familirae with LayoutAnimated...i need just to move up label.Text every 200ms UP.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
why not use ONLY setLayout Animated? no need for the timer

The first parameter on setLayout animated is a duration time for the animation, so you set your duration and the target final position, ans it should animate as expected
 
Upvote 0
Top