B4A Library [B4X] [XUI] Scrolling Label

Discussion in 'Additional libraries, classes and official updates' started by Erel, Oct 29, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User


    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 you should add this code to Activity_Resume:
    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
    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).

    Attached Files:

    Last edited: Apr 26, 2018
    jinyistudio, jmon, TnP and 22 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    V1.10 released: Text color can be set in the designer (under Text properties).
  3. Patent

    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:

    Private Sub StartScrolling (p As B4XView, OriginalWidth As Float)
        taskIndex = taskIndex + 
    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
    If myIndex <> taskIndex Then Return
                p.SetLayoutAnimated(duration, -(p.Width - OriginalWidth), p.Top, p.Width, p.Height)
    If myIndex <> taskIndex Then Return
    00, p.Top, p.Width, p.Height)
    If myIndex <> taskIndex Then Return
    End If
    End Sub
    inakigarm likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Add #If B4J to make it cross platform.
  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