Android Question ScrollView2D

tomoshea

Member
Licensed User
Longtime User
Hi,
I want to use Scrollview 2D and I need to identify the direction of the scrolling (left,right,up,down).
What is the best way to do this?
Kind Regards,
Tom
 
There's an example somewhere.. I'll see if I can dig it out.

found it : http://www.b4x.com/android/forum/threads/scrollview-example.6612/

I think if you download the zip, it works out the starting and ending point of the finger, you then need to do some maths to work out which direction it's moved in..

I'll see if I can dig the code out, it might not be in the Zip above.. but it is around this example.

It is in that example above, look at the Sub Panels_Touch. It has some tolerances built in and then you need to work out the 'major' direction being inferred by the User.
 
Last edited:
Upvote 0
Thank you eps - I will have a look at the link above.
Will let you know how I get on.
Have a nice day.
Regards,
Tom
 
Upvote 0
Hi,
I want to use Scrollview 2D and I need to identify the direction of the scrolling (left,right,up,down).
What is the best way to do this?
Kind Regards,
Tom
Very easy:
Code: Copy
Sub sv2d_ScrollChanged(PosX As Int, PosY As Int)
    If OldPosX > PosX Then going Left Else going Right
    If OldPosY > PosY Then going Up Else going Down
    OldPosX = PosX
    OldPosY = PosY
End Sub
 
Upvote 0
Very easy:
Code: Copy
Sub sv2d_ScrollChanged(PosX As Int, PosY As Int)
    If OldPosX > PosX Then going Left Else going Right
    If OldPosY > PosY Then going Up Else going Down
    OldPosX = PosX
    OldPosY = PosY
End Sub

Thanks for the reply.
It seem not to do what I expected.
When I scroll say left this event is triggered multiple times gives different directions.
Both OldPosX can be > PosX and OldPosY can be > PosY at the same time so if I check PosX first I get going Left or Right
but if I check PosY first I get going Up or Down.
I was thinking that I could use the property ScrollingIsFinished and work out the direction by using the starting X Y positions and
the end x y positions but I am unsure where to put the line to check ScrollingIsFinished = true so that I can get the end X Y positions.
If I put it in sv2d_ScrollChanged It is checked multiple times which is no use.
I am trying to do the following
I have a scrollview loaded with a layout and when I scroll left or right I want to load a new page
but when I scroll up or down I want to just scroll the layout in the scrollview on the current page up or down.
Kind Regards,
Tom
 
Upvote 0
Thanks for the reply.
It seem not to do what I expected.
When I scroll say left this event is triggered multiple times gives different directions.
Both OldPosX can be > PosX and OldPosY can be > PosY at the same time so if I check PosX first I get going Left or Right
but if I check PosY first I get going Up or Down.
I was thinking that I could use the property ScrollingIsFinished and work out the direction by using the starting X Y positions and
the end x y positions but I am unsure where to put the line to check ScrollingIsFinished = true so that I can get the end X Y positions.
If I put it in sv2d_ScrollChanged It is checked multiple times which is no use.
I am trying to do the following
I have a scrollview loaded with a layout and when I scroll left or right I want to load a new page
but when I scroll up or down I want to just scroll the layout in the scrollview on the current page up or down.

What you explain is quite different from the initial question:
tomoshea said:
I need to identify the direction of the scrolling (left,right,up,down). What is the best way to do this?

What you need is probably not a ScrollView2D but an AHViewPager.
 
Upvote 0
What you explain is quite different from the initial question:


What you need is probably not a ScrollView2D but an AHViewPager.

I cannot use the AHViewPager. I have been down that road already.
It would take too long to explain why.
I do not need to scroll sideway I only need to scroll up,down,left and right.
If I can only find out when the scroll is completely finished I can make it work.
So is the ScrollingIsFinished the property that I should use?
If so how does one use the ScrollingIsFinished property?
Regards
Tom
 
Upvote 0
ScrollingIsFinished is useless here. It is meant to detect the end of a scroll initiated by a fling gesture or when you change programmatically the scroll position. It will always report true if you scroll slowly with your finger.
You have to define what means "the scroll is completely finished" (and when it starts) before going further. Once done, my solution in post #4 have to be modified to take values at the beginning and at the end to compare them.
 
Upvote 0
You didn't understand me. "End" means nothing in a flow of events. What's the end for you? After 20 milliseconds of idleness? After 3 scroll events? I provided you with a solution (post #4) that tells you the scrolling direction for each event. When an event is raised, the scroll is finished (if you didn't fling), so when do you consider it is really finished for you?
 
Upvote 0
Back
Top