Smoothly scroll to specified position in Android gallery
Is there a sane way to programatically scroll to show a specific component in a Gallery 开发者_开发技巧- the equivalent of setSelection(int) but with smooth scrolling rather than a direct jump?
I think I've found an easy way to do it ! It consists of calling the onFling() method directly...
MotionEvent e1 = MotionEvent.obtain(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN, 89.333336f, 265.33334f, 0);
MotionEvent e2 = MotionEvent.obtain(
SystemClock.uptimeMillis(),
SystemClock.uptimeMillis(),
MotionEvent.ACTION_UP, 300.0f, 238.00003f, 0);
gallery.onFling(e1, e2, -800, 0);
There should be a better way to do it. onFling() should be called when the Gallery gets flinged, not to fling it.
精彩评论