Android Question LibGDX - ScrollPane - ScrollTo not scrolling to bottom

Discussion in 'Android Questions' started by Jeffrey Cameron, Mar 18, 2015.

  1. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    I'm trying to create a "chat window" type of effect using a ScrollPane to contain the chat log. I've added an lgScn2DScrollPane to my stage which contains a group that contains a table. At runtime, I add rows containing a label to the table and then resize the group containing the table to accommodate the height of the new label.

    This works fine, what is not working is when after adding the new line I issue a .ScrollTo(0, 0, width, height) it doesn't scroll. I've also tried .ScrollPercent = 100 which has the same effect. It acts as if the maximum scroll height is staying the same until after the render event. I even tried moving the ScrollTo to the render event just prior to the Stage.Draw from the "add line" routine and it makes no difference.

    I can manually scroll to the bottom via the scrollbar or swipe to scroll but every time I add a new "line" to the display, the .ScrollTo method in code only scrolls down to the previously added line.

    How can I have it scroll properly, or is there a more suitable way of creating a "chat text" type display?

    Thanks in advance,
    - Richard
  2. Jeffrey Cameron

    Jeffrey Cameron Active Member Licensed User

    I've achieved the desired effect by adding two Boolean flags to the project, let's call them Flag1 and Flag2. When I add a new row with a text label to the ScrollPane's table, I set Flag 1 = True and Flag 2 = False.

    Then in the render event, I check the flags in this order (pseudo-code):
    If Flag2 Then
          Flag2 = 
    ScrollPane.scrollTo(00ScrollPane.Width, ScrollPane.Height)
    End If
    If Flag1 Then
          Flag1 = 
    ScrollPane.LayoutEnabled = False
          groupHoldingTable.Height = ScrollpaneTable.Height
    ScrollPane.LayoutEnabled = True
          Flag2 = 
    End If
    If anyone has a better solution, please feel free to post it.
  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