scrolling labels

Fox

Active Member
Licensed User
Longtime User
is it possible to make a scrolling label like an credit box??
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The attached code module allows you to scroll multiple labels.

To use it you should add the module to your project and then add code similar to:
B4X:
Sub Process_Globals
    Dim Timer1 As Timer 'The timer that controls the animation
End Sub

Sub Globals
    Dim Label1 As Label
    Dim Label2 As Label
    Dim ListOfScrollingLabels As List 'List of scrolling labels
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        timer1.Initialize("Timer1", 20)
    End If
    ListOfScrollingLabels.Initialize
    Label1.Initialize("") 'Not needed if the label is added with the designer
    Label2.Initialize("")
    Activity.AddView(Label1, 10dip, 10dip, 150dip, 100dip)
    Activity.AddView(Label2, 10dip, 130dip, 200dip, 100dip)
    ListOfScrollingLabels.Add( _ 
        ScrollingLabels.StartScrolling(Label1, "This is a very very very long sentence."))
    ListOfScrollingLabels.Add( _ 
        ScrollingLabels.StartScrolling(Label2, "jskldfjlskdj fsldk fjskldfj lskdfj lkewj flewk fjwklef ."))
    Timer1.Enabled = True 'Start the scrolling
End Sub

Sub Timer1_Tick
    ScrollingLabels.TimerTick(ListOfScrollingLabels)
End Sub
 

Attachments

  • ScrollingLabels.bas
    1.5 KB · Views: 1,420
  • Like
Reactions: fsu
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi Erel,

Thanks for this code, just what I needed.

@All

I merged the code with my Species Translator and run into 2 problems which I can´t solve :eek:

1. On selecting a long name first (> 24 characters) some labels dissapear in the translations screen. Eg. B -> Baikal Teal x Eurasian Wigeon.
Then Next search-button and B -> Baikal Teal. All labels appear.

2. The previous label´s text remains when again a long name is selected.

Tried everything I could think of, also in the ScrollingText module.
1. Wrong coding order?

Thanks for any help.

Helen
 

Attachments

  • SpeciesTr.zip
    22.7 KB · Views: 782
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

After changing the app I can't get the scrolling labels to work correctly :BangHead:

In the ScrollingLabels module line 63: when I set it on False, the text is not renewed and when I set it on True the background color disappears.

The Scrolling should appear on smaller devices when you e.g. select "Hybrid Lesser White-fronted Goose x Emperor Goose", also as Display Language.

Thank you very much in advance and regards,
Helen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I looked at your code.
If you replace:
SL.Canvas.DrawRect(SL.DestRect, Colors.Transparent, True, 0)
by
SL.Canvas.DrawRect(SL.DestRect, Colors.White, True, 0)
it works, the color is of no inmportance could be other than white.

The problem is the following:
- the ScollingLabels are based on transparent Labels.
- you try to use Labels with a GradientDrawable.

The only drawback is that the labes have one color and no rounded corners.

If you really want gradient colors it would need a much deaper look into the code.

Best regards.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi Klaus,

What would I do without you :)
I got the labels with the square corners as well (tried everything).
Guess you can imagine that I really want to use the cornerradius. Gradient colours are much less important.

In the old module "Translations" (still in the project) it did work well.
So I think that building the bird name labels differently in the "Vertalingen" module is causing it.
Now I'm crossing my fingers that you find the solution.

Best regards,
Helen.

Ps. Went on wintersport to Crans Montana once. I should have brought you a big bouquet of flowers then, in advance for everything you do.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Helen,
Now I'm crossing my fingers that you find the solution.
Please leave me a few days, because the next days I won't have much time. But will look at it.

Went on wintersport to Crans Montana once..
I live quite close to Crans Montana, less than 50km, in the Rhône valley. If you once come over here, please let me know, we could meeet and why not drink some good wine.

Best regards.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi Klaus,

Of course that goes for you as well, when you get to the south of Spain.
I will wait patiently for a solution for the scrollinglabels, since I ran out of ideas.

Best regards,
Helen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Helen,
Here you are, it took me a while, but I got it.
I was looking for bitmaps and then with the GradientDrawable, then I saw that you already tried it too.
The solution is to set the Label.Background to the GradientDrawable.
But then the Label Bitmap is different and needs to reinitialize the Canvas.

B4X:
Sub TimerTick (Labels As List)

    Dim clrs(2) As Int
        clrs(0) = Colors.RGB(128, 128, 128)
        clrs(1) = Colors.RGB(255, 255, 255)
    Dim gdRad As GradientDrawable
    gdRad.Initialize("LEFT_RIGHT", clrs)
    gdRad.CornerRadius = 5

    For i = 0 To Labels.Size - 1
        Dim SL As ScrollingLabel
        SL = Labels.Get(i)

        SL.SrcRect.Left = SL.SrcRect.Left + 1dip
        SL.SrcRect.Right = SL.SrcRect.Left + SL.lbl.Width
        If SL.SrcRect.Right > SL.Bitmap.Width Then
            SL.SrcRect.Left = 0
            SL.SrcRect.Right = SL.SrcRect.Left + SL.lbl.Width
        End If
        
        SL.lbl.Background = gdRad
        SL.Canvas.Initialize(SL.lbl)
        SL.Canvas.DrawBitmap(SL.Bitmap, SL.SrcRect, SL.DestRect)
        SL.lbl.Invalidate
    Next
End Sub
Attached the modified version. I had to comment out the lines refering to AdMob.

Best regards.
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Wowwwwww, that was my reaction. Not sure if you heard it in Switserland ;)
My compliments and most of all a BIG thank you!!!

Initializing and I still don't understand each other very well but I will get there one day.

My very best wishes for a fantastic 2012 especially for you.
Helen.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Initializing and I still don't understand each other very well but I will get there one day.
Some explanations:
- when we set a new Backgound to the label
- the label bitmap is a new one
- but the canvas still points to the previous one
- so we need to reinitialize the canvas to make it point to the new bitmap.
At least that's how I understand it.

Best regards and all the Best wishes for the new year.
 
Upvote 0

M.LAZ

Active Member
Licensed User
Longtime User
The attached code module allows you to scroll multiple labels.

To use it you should add the module to your project and then add code similar to:
B4X:
Sub Process_Globals
    Dim Timer1 As Timer 'The timer that controls the animation
End Sub

Sub Globals
    Dim Label1 As Label
    Dim Label2 As Label
    Dim ListOfScrollingLabels As List 'List of scrolling labels
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        timer1.Initialize("Timer1", 20)
    End If
    ListOfScrollingLabels.Initialize
    Label1.Initialize("") 'Not needed if the label is added with the designer
    Label2.Initialize("")
    Activity.AddView(Label1, 10dip, 10dip, 150dip, 100dip)
    Activity.AddView(Label2, 10dip, 130dip, 200dip, 100dip)
    ListOfScrollingLabels.Add( _
        ScrollingLabels.StartScrolling(Label1, "This is a very very very long sentence."))
    ListOfScrollingLabels.Add( _
        ScrollingLabels.StartScrolling(Label2, "jskldfjlskdj fsldk fjskldfj lskdfj lkewj flewk fjwklef ."))
    Timer1.Enabled = True 'Start the scrolling
End Sub

Sub Timer1_Tick
    ScrollingLabels.TimerTick(ListOfScrollingLabels)
End Sub


Hi Erel,

How can i change the direction of scrolling Right to Left, i try a lot in the module to make any change in the direction .
 
Upvote 0
Top