Smooth scrolling with inertia and edge resistance/snapback?

Use a OnGestureListener To provide smooth scroll, create a scroller (in your custom view). When the gesture listener detects a fling event, set the scroller up. Then, override your custom view's computeScroll() method Check this example to know how to implement it int lastX; int lastY; Scroller scroller; @Override public void computeScroll() { if (scroller.

ComputeScrollOffset()) { if (!scrolledLastFrame) { lastX = scroller.getStartX(); lastY = scroller.getStartY(); } int dx = scroller.getCurrX() - lastX; int dy = scroller.getCurrY() - lastY; lastX = scroller.getCurrX(); lastY = scroller.getCurrY(); doScroll(dx, dy); scrolledLastFrame = true; } else { scrolledLastFrame = false; } } public void doFling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) { scroller. Fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY); invalidate(); } public void doScroll(int dx, int dy) { currentX+=dx; currentY+=dy; invalidate(); } private class ProgramGestureListener extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { doScroll(distanceX, distanceY); return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { int max_left = getMaxHorizontalScroll(); int max_top = getMaxVerticalScroll(); int min_left = getMinHorizontalScroll(); int min_top = getMinVerticalScroll(); int startX = getCurrentHorizontalScroll(); int startY = getCurrentVerticalScroll(); doFling(startX, startY, (int) -velocityX, (int) -velocityY, min_left, max_left, min_top, max_top); return true; } }.

Use a OnGestureListener. To provide smooth scroll, create a scroller (in your custom view). When the gesture listener detects a fling event, set the scroller up.

Then, override your custom view's computeScroll() method. Check this example to know how to implement it. Int lastX; int lastY; Scroller scroller; @Override public void computeScroll() { if (scroller.

ComputeScrollOffset()) { if (!scrolledLastFrame) { lastX = scroller.getStartX(); lastY = scroller.getStartY(); } int dx = scroller.getCurrX() - lastX; int dy = scroller.getCurrY() - lastY; lastX = scroller.getCurrX(); lastY = scroller.getCurrY(); doScroll(dx, dy); scrolledLastFrame = true; } else { scrolledLastFrame = false; } } public void doFling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY) { scroller. Fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY); invalidate(); } public void doScroll(int dx, int dy) { currentX+=dx; currentY+=dy; invalidate(); } private class ProgramGestureListener extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { doScroll(distanceX, distanceY); return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { int max_left = getMaxHorizontalScroll(); int max_top = getMaxVerticalScroll(); int min_left = getMinHorizontalScroll(); int min_top = getMinVerticalScroll(); int startX = getCurrentHorizontalScroll(); int startY = getCurrentVerticalScroll(); doFling(startX, startY, (int) -velocityX, (int) -velocityY, min_left, max_left, min_top, max_top); return true; } }.

I didn't know about computeScroll(), it's way better than use computeScrollOffset() inside onDraw() like I did. +1 – bigstones Feb 15 at 13:10 Thanks! I've tried to implement a solution based on your answer, but my computeScroll() is not called for some reason.Do I have to connect Scroller and View somehow?

– Fabian Feb 18 at 13:21 to use a GestureListener, you also need to use a GestureDetector. Send touch events to the detector and set the ProgramGestureListener as the detector's listener. Maybe useful: stackoverflow.

Com/questions/937313/… – Pedro Loureiro Feb 18 at 15:30.

Use the Scroller class, I posted an example of use here. If you're on API 9 you could use OverScroller I think.

I implemented basic scrolling via touch dragging and multitouch zooming for a custom view. This works well, but now I'd like to add some advanced features. For example, in the Google Maps application, when you drag around the screen, after you stop dragging it will still continue to move a bit (inertia).

And some browsers (e.g. IPad Safari) allow you to drag the screen further than the visible area of the website, but then the screen will quickly snap back to the edge of the website. I'd now like to implement something similar, but to do that I need to change the active screen region after the touch events happened in regular intervals to perform the animation. How can I do that?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions