Android Question LibGDX - ScrollPane - ScrollTo not scrolling to bottom

Jeffrey Cameron

Well-Known 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
 

Jeffrey Cameron

Well-Known 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):
B4X:
 If Flag2 Then
      Flag2 = False
      ScrollPane.scrollTo(0, 0, ScrollPane.Width, ScrollPane.Height)
 End If
 If Flag1 Then
      Flag1 = False
      ScrollPane.LayoutEnabled = False
      ScrollpaneTable.pack
      groupHoldingTable.Height = ScrollpaneTable.Height
      ScrollPane.LayoutEnabled = True
      Flag2 = True
 End If
If anyone has a better solution, please feel free to post it.
 
Top