Android Tutorial Scrolling Marquee with ListViews

Wanted to have a smooth scrolling message for an initial screen in one of my programs, and couldn't find anything pre-built into Android, so of course, something that should have taken just a few lines of code, turned into a couple day extravaganza to develop a re-usable module for future projects! :D

Attached find my code for anyone else that desires something like this as a starting point.

It uses a canvas attached to a label, with movement of the text controlled by a timer. Scrolling speed can be controlled by timer_tick ms and by setting the number of pixels that text moves each tick.

Ability to add and subtract messages into the queue is demonstrated with this demo.

Oh, and it is type advMarquee, because my first marquee used simple text control on the label, but that proved very, very choppy... especially with different languages. (and it was type Marquee :sign0013:)

Does require the very convenient ADR Strings module by Margret.
 

Attachments

  • AdvMarquee.91.zip
    12.2 KB · Views: 929

NFOBoy

Active Member
Licensed User
Longtime User
I did look there, but did not see that it actually showed a Scrolling Message.

Just showed ... to indicate that there was more message to show, and user interaction required to move the message. (and more coding to get that done)

This sample actually loads up different messages, goes thru them in order along the display (at variable rates of movement), with ability to add and delete messages "on the fly", and in either direction.

Also, by using the Canvas method, the scrolling can be very smooth. (simple text manipulation caused very jerky motion, especially with Foreign Languages)

Did I miss something in the other sample? :confused:
 
Last edited:

NFOBoy

Active Member
Licensed User
Longtime User
Ok

I gave that a try... and again I :BangHead: until I saw thedesolatesoul response about adding the other runmethod2


B4X:
Sub Globals    
Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)    
Activity.LoadLayout(1)    
Label1.Text = "this is a very long text."    
SetEllipsize(Label1, "MARQUEE")
End Sub

Sub SetEllipsize(TextView As Label, Mode As String)   
Dim r As Reflector    
r.Target = TextView    
r.RunMethod2("setLines", 1, "java.lang.int")   
r.RunMethod2("setHorizontallyScrolling", True, "java.lang.boolean")     
r.RunMethod2("setEllipsize", Mode, "android.text.TextUtils$TruncateAt")
r.RunMethod2("setSelected", True, "java.lang.boolean")
End Sub

This works now... and would have been a lot, lot easier than what I put together... but mine does have some more flexibility, but I am still a :sign0104:

Of note, I did search for Marquee, and only a just a few topics... B4A is definitely a dream for me for developing, but I am still learning how to use a few of the libs to get more functionality, but documentation is so scarce sometimes... Thankfully many, many smart and friendly people on here!
 

lorebarita

Member
Licensed User
Longtime User
NFOBoy you code was working fine and I liked it a lot but I upgraded my B4A and the sample code and am now getting this error when I run you sample from the forum


Parsing code. 0.01
Compiling code. Error
Error compiling program.
Error description: Object reference not set to an instance of an object.
Occurred on line: 191
Dim newarray(mqe.MessageArray.Length + 1) As String
Word: messagearray
 

lorebarita

Member
Licensed User
Longtime User
You are so right man. It worked very well I changed the class module AdvMarquee to AdvMarquee2 and all its references and it worked. How do u know soo much? am working hard to be like you. Thanks indeed
 
Top