B4A Library [B4X] [XUI] Scrolling Label

Erel

Administrator
Staff member
Licensed User
scrolling-label.gif


A custom view with a label that scrolls automatically when the text is wider than the label.
The class is supported by B4A, B4i and B4J. It depends on XUI v1.46+.

Note that in B4A, if not using B4XPages, you should add this code to Activity_Resume:
B4X:
Sub Activity_Resume
   For Each v As View In Activity.GetAllViewsRecursive
     If v.Tag Is ScrollingLabel Then
       Dim sl As ScrollingLabel = v.Tag
       sl.Text = sl.Text 'this will cause the labels to scroll
     End If
   Next
End Sub
A B4J example is attached. The class is inside the zip.

V1.10 - Text color can be set in the designer (under Text properties).
 

Attachments

Last edited:

Patent

Member
Licensed User
thanks for this, erel.

Hint for using in B4J (could not test it in others, maybe its the same there):

If you minimize a app in which you use a scrolling label, the cpu load increases factor 4 or more (think it depends on invisible layout-rendering!?).
So my solution is a little add in your class-sub -StartScrolling- and then it works fine:

B4X:
Private Sub StartScrolling (p As B4XView, OriginalWidth As Float)
    taskIndex = taskIndex + 1
    Dim myIndex As Int = taskIndex
    Dim duration As Int = p.Width / WidthPerSecond * 1000
    Do While True
        'this loop causes higher cpu load when app is minimized!!!???????
        'not minimized is OK!!!
        'so, check if minimized and then sleep:
        Dim st As JavaObject=Main.yourmainform
        Dim sta As JavaObject=st.GetFieldJO("stage")
        If sta.RunMethod("isIconified",Null)=True Then
            Sleep(2000)
            If myIndex <> taskIndex Then Return
        Else
            p.SetLayoutAnimated(duration, -(p.Width - OriginalWidth), p.Top, p.Width, p.Height)
            Sleep(duration)
            If myIndex <> taskIndex Then Return
            Sleep(800)
            p.SetLayoutAnimated(0, 0, p.Top, p.Width, p.Height)
            If myIndex <> taskIndex Then Return
        End If
    Loop
End Sub
greets
 
Top