Android Question [XUI] Scrolling label text alignment

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
I'm using scrolling label by @Erel (https://www.b4x.com/android/forum/threads/b4x-xui-scrolling-label.85516/) and it works very well but I can't set the text horizontal alignment.

When the text doesn't scroll (short than the label width) I wish that the text is horizontally aligned in the center.
To set it I'm using the B4A Designer and for the scrolling label I choose "CENTER_HORIZONTAL" (Horizontal Alignment) but it is displayed as LEFT alignment.

How to solve this ?
Thanks in advance for any suggestion.

Luca.
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
The solution you are using provides the entirety of the source code. You need to modify it to do what you need.

Having said that, and briefly looking at the source code, I would start with modifying the setText method to adjust the alignment, something such as:
B4X:
    If originalTextWidth <= mBase.Width Then
        xlbl.Text = t
        xlbl.Gravity = Gravity.Center
        p.Tag = "static"
        StopScrolling
    Else
        p.Tag = ""
        Dim duplicateText As String = t & "   " & t
        Dim Width As Float = MeasureTextWidth(duplicateText, fnt)
        p.Width = Width
        xlbl.Width = Width
        xlbl.Text = duplicateText
        xlbl.Gravity = Gravity.LEFT
        StartScrolling (p, originalTextWidth)
    End If
And see if that accomplishes what you're looking for.
 
Upvote 0
Top