scrolling labels

Discussion in 'Android Questions' started by Fox, Apr 23, 2011.

  1. Fox

    Fox Active Member Licensed User

    is it possible to make a scrolling label like an credit box??
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Do you want the text to scroll automatically?
     
  3. Fox

    Fox Active Member Licensed User

    yes an automatically text scroll.. maybe if the text is bigger than the label high... is this possible?
     
  4. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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, 10dip10dip150dip100dip)
        
    Activity.AddView(Label2, 10dip130dip200dip100dip)
        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
     

    Attached Files:

    fsu likes this.
  5. Merlot2309

    Merlot2309 Active Member Licensed 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
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    The database file is not included in the zip file. You should add it by going to the Files tab and choose Add Files (otherwise it will not be included in the zip file).
     
  7. Merlot2309

    Merlot2309 Active Member Licensed User

    Oeps, second try
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    I haven't found the root of this problem. Is it possible that you are loading the same layout file again each time? If you are not removing the previous views first then you will get a stack of labels.

    I recommend you to use a second activity for the translation page. It will be easier to handle.
     
  9. Merlot2309

    Merlot2309 Active Member Licensed 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.
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    I looked into the code. However I cannot say what is the problem.

    The purpose of:
    Code:
    SL.Canvas.DrawRect(SL.DestRect, Colors.Transparent, False0'Should be True
    Is to erase the label.
    The next line should draw the bitmap.

    Try to debug it by drawing the bitmap on a visible panel.
     
  11. klaus

    klaus Expert Licensed 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.
     
  12. Merlot2309

    Merlot2309 Active Member Licensed 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.
     
  13. klaus

    klaus Expert Licensed User

    Hi Helen,
    Please leave me a few days, because the next days I won't have much time. But will look at it.

    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.
     
  14. Merlot2309

    Merlot2309 Active Member Licensed 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.
     
  15. klaus

    klaus Expert Licensed 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.

    Code:
    Sub TimerTick (Labels As List)

        
    Dim clrs(2As Int
            clrs(
    0) = Colors.RGB(128128128)
            clrs(
    1) = Colors.RGB(255255255)
        
    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.
     
  16. Merlot2309

    Merlot2309 Active Member Licensed 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.
     
  17. klaus

    klaus Expert Licensed User

    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.
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    As always, you are correct.
     
  19. lazreg

    lazreg Active Member Licensed User


    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 .
     
  20. klaus

    klaus Expert Licensed User

    Attached you find a new version where you can select the direction.
     

    Attached Files:

Loading...
  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