Hey, I am learning Android. I struggle to properly...
# android
v
Hey, I am learning Android. I struggle to properly capture and react to the user's horizontal scrolling event across the screen. I'd like to touch the screen and with a horizontal scrolling motion I would like to update a number (TextView) on the screen, much like a traditional slider widget but the slider itself is the entire screen. I think I need to fiddle with
GestureDetector
like shown here. Can anyone link me some examples that I can learn from, please? I'm digging Google hard, but since I'm new, it's hard to ask the right questions.
I was referring to sliders like this 

https://support.ptc.com/help/thingworx_hc/thingworx_8_hc/en/ThingWorx/images/SliderWidgetBeta.png

p
This probably a good starting point: https://developer.android.com/training/gestures/detector with this you can track the user movement (touch and move finder) and also fling (typically the movement you do when you want to scroll a long distance where you raise your finger from the screen while it’s still moving). That link shows how to intercept touch events on a view or an activity. Then you need to decide how to translate those movements to a change in your value. Because with those APIs tell you the finger moved X pixels. But then you need to decide by how much to update your number. Tip: think of screens with different sizes and screens of the same size but different densities. On the top of that, you also need to keep in mind whether the movement was “mostly” horizontal, vertical, or diagonal. (What you do in those scenarios is also up to you). But go one step at a time, and play with the different scenarios and find something to works reasonably well 🙂
Feel free to read the other articles in that training section (using touch gestures) as there are useful things in the other articles too. Specially the track touch and gesture movements.
v
Thanks @pedro , that tutorial I already read and been trying to understand the reported values of the MotionEvents, but I am looking for a tutorial where I could find examples how to interpret these values where they make sense in a seekbar kinda way.
p
that depends a lot on your case. It depends what the number means, by how much it can change, and how much detail the user needs. So there’s not just one answer to that problem.
You can say left of the screen is the minimum possible value, right is max value. and if you swipe for 10% of the screen, the value moves by 10% of the range. This is a starting point but doesn’t work well for all cases
v
Ok @pedro at least I know I was digging at the right place 🙂 Thank you!
👍 1