ScrollView2D question

basil99

Active Member
Licensed User
Longtime User
Hi

Lets say, I have s ScrollView2D with some views and its panel width is N*ScreenWidth. ScroolView2D is invisible ( ScroolView2D.Visible = False ), but on some button click I reveal it and want to scroll it to, say, K ( K = 0,1,..., N-1 ) position. My code is:

B4X:
dim SV2d as ScrollView2d

' add some views and set panel width

SV2d.Panel.Width = N*ScreenWidth

' then on button click i want to scroll it to the K pos:

sub Button_Click

    SV2D.Visible = True
    SV2D.HorizontalScrollPosition = K*ScreenWidth

end sub

Unfortunatly, nothing happens. ScrollView2D panel don't scroll

So, what is my error here ?

Thank you
 

basil99

Active Member
Licensed User
Longtime User
thanks for DoEvents tip. Unfortunatly, one DoEvent is not enough, but this sequence of lines seems to work fine:

B4X:
sun button_click

    SV2D.Visible = True
    SV2D.BringToFront
    DoEvents
    SV2D.HorizontalScrollPosition = K * ScreenWidth
    DoEvents
    SV2D.Invalidate

end sub
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
thanks for DoEvents tip. Unfortunatly, one DoEvent is not enough, but this sequence of lines seems to work fine:

B4X:
sun button_click

    SV2D.Visible = True
    SV2D.BringToFront
    DoEvents
    SV2D.HorizontalScrollPosition = K * ScreenWidth
    DoEvents
    SV2D.Invalidate

end sub

This code works (I tried it):
B4X:
SV2D.Visible = True
DoEvents
SV2D.HorizontalScrollPosition = K * ScreenWidth
Without the context, it's difficult to say why you need to add something else. There's no logical explanation for:
B4X:
DoEvents
SV2D.Invalidate
This code should be completely useless.
The first DoEvents after "visible = true" is mandatory because it lets some time to the B4A message handler to make the ScrollView visible (to process the UI message). The scroller does not work as expected if the ScrollView is not already visible.
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
This code works (I tried it):
B4X:
SV2D.Visible = True
DoEvents
SV2D.HorizontalScrollPosition = K * ScreenWidth
Without the context, it's difficult to say why you need to add something else. There's no logical explanation for:
B4X:
DoEvents
SV2D.Invalidate
This code should be completely useless.
The first DoEvents after "visible = true" is mandatory because it lets some time to the B4A message handler to make the ScrollView visible (to process the UI message). The scroller does not work as expected if the ScrollView is not already visible.

Will back to this soon, probably you're right - just post the code that finally start to work ) Pretty sure I can remove this lines.

Btw, you got my emails ? )
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
correct, this 2 last lines of code are useless, they appear in sub when i try to make it work.

Thanks again )
 
Upvote 0
Top