Scrolling in all directions

2019-07-13 03:10发布

问题:

I've been trying to implement an activity where I can scroll horizontally and vertically in all directions, I've tried out using gesturelistener and the "scrollby" method in View, however the screen is still static. I've also done a nested horizontal and vertical scroll in xml, however this only gives me scrolling to the right of the screen and bottom. It seems i cant move in the negative x direction.

Thanks.

回答1:

  • Customize ViewGroup
  • Override OnTouchEvent
  • Detect MotionEvents
  • Track Finger Points
  • Calculate Distance Moved
  • Modify the X and Y of the canvas Content Rectangle.
  • Finally in your layout add child views you want to scroll inside this ViewGroup

Source code: https://gist.github.com/jayakrishnan-pm/ScrollingLayout.java