Android Question Auto-scrolling text

ivavilagu

Member
Licensed User
Longtime User
I need to show a text like the final credits of a movie. I put the text in a label and with the animation library move the label from down to up the screen. This is the code:

B4X:
dim a as animation
dim lbl2 as label

lbl2="Large large large text...." // the real text is really large, many lines
Activity.AddView(lbl2, 5%x, 0, 90%x, 100%y)

a.InitializeTranslate("",0,100%y,0%x,-200%y)
a.Duration=128000
lbl2.Visible= True
a.start(lbl2)

The text is shown as well, like I want. But when I have tested the app in differents resolutions devices, the duration of animation changes. In some cases the duration is shorter and in other cases is longer. I'm not be able to check when the animation finishes. Until I discovered that I used a Timer with the same duration as the animation.

Is there any way to get the finish of the animation? Or is there any way to get the same duration of the animation independently of the resolution?
 

ilan

Expert
Licensed User
Longtime User
u can set a point where the animation should stop
for example: if label1.top starts at 100%y then finish the animation when label1.bottom = 0

in your case it's

if lbl2.top = -200%y then
'timer.enable = false
'a.stop
msgbox("animation finished","")
end if
 
Upvote 0

ivavilagu

Member
Licensed User
Longtime User
The animation duration is not affected by the screen resolution.

You can handle the AnimationEnd event.

Thanks Erel. I forget the ending event.
 
Upvote 0

ivavilagu

Member
Licensed User
Longtime User
u can set a point where the animation should stop
for example: if label1.top starts at 100%y then finish the animation when label1.bottom = 0

in your case it's

if lbl2.top = -200%y then
'timer.enable = false
'a.stop
msgbox("animation finished","")
end if


Thank you for the code. I have used the AnimationEnd event as Erel said. I have modified the animation line to scroll up the label exactly the height of the label.

B4X:
a.InitializeTranslate("Animacion",0,100%y,0%x,-lbl2.Height)


Thank you both!!!!
 
Upvote 0
Top