T tomoshea Member Licensed User Longtime User Aug 19, 2013 #1 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
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
eps Expert Licensed User Longtime User Aug 19, 2013 #2 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: Aug 19, 2013 Upvote 0
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.
T tomoshea Member Licensed User Longtime User Aug 20, 2013 #3 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
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
Informatix Expert Licensed User Longtime User Aug 20, 2013 #4 tomoshea said: 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 Click to expand... 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
tomoshea said: 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 Click to expand... 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
T tomoshea Member Licensed User Longtime User Aug 20, 2013 #5 Informatix said: 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 Click to expand... 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
Informatix said: 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 Click to expand... 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
Informatix Expert Licensed User Longtime User Aug 20, 2013 #6 tomoshea said: 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. Click to expand... 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? Click to expand... What you need is probably not a ScrollView2D but an AHViewPager. Upvote 0
tomoshea said: 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. Click to expand... 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? Click to expand... What you need is probably not a ScrollView2D but an AHViewPager.
T tomoshea Member Licensed User Longtime User Aug 21, 2013 #7 Informatix said: What you explain is quite different from the initial question: What you need is probably not a ScrollView2D but an AHViewPager. Click to expand... 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
Informatix said: What you explain is quite different from the initial question: What you need is probably not a ScrollView2D but an AHViewPager. Click to expand... 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
Informatix Expert Licensed User Longtime User Aug 21, 2013 #8 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
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.
T tomoshea Member Licensed User Longtime User Aug 21, 2013 #9 How do I know that it is at the end so that I can process the values stored ( start and finish)? Upvote 0
Informatix Expert Licensed User Longtime User Aug 21, 2013 #10 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
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?
T tomoshea Member Licensed User Longtime User Aug 22, 2013 #11 Thanks for all your help. Kind Regards Tom Upvote 0