Android Code Snippet CallSubDelayed & ScrollView.ScrollPosition

Often a Scrollview doesn't scroll as you expect when you add a lot of views to it and then want to scroll it to the last added view. It seems as the message isn't properly handled because the system is still busy with the SV itsself.

The following code works for me. Just put the Scroll command to another sub and call it with "CallSubDelayed2".

B4X:
Sub AddManyViewsToASrollView

'add a lot of views in a loop

CallSubDelayed2(Me,"Scroll2Pos",SV.Panel.Height) 'scrolls to the panel height = last added view
  
End Sub

Sub Scroll2Pos (pos As Int)
    SV.ScrollPosition=pos 'SV is defined in globals
End Sub

Of course you can change the code and call the sub with the SV as a parameter to make it more flexible.
 
Top