How can i make my page slide as the user slides finger on the screen in android? Any example code?
I just require the same feel as it is on my android g-phone's home screen.The screen moves as the finger moves(also includes the elastic effect).
How can i make my page slide as the user slides finger on the screen in android? Any example code?
I just require the same feel as it is on my android g-phone's home screen.The screen moves as the finger moves(also includes the elastic effect).
Check out this tutorial and its follow up on warriorpoint. They explain how to use the ViewFlipper to smoothly animate the transition from one screen to another, and then in the second part how to do this using touch control. Note, these are whole-screen transitions not panning around on an existing page. For panning, e.g. on an oversized image that doesn't fit in the screen, check out Android BigImage. Depending on what you're trying to do these might be overkill, but it's not 100% clear what you're trying to achieve.
You will need Gesture detector - the classes / interfaces under considerations are:
1. android.view.GestureDetector
2. android.view.GestureDetector.SimpleOnGestureListener
Method of interest is onFling
.
Now, based on the X, Y and the velocity in respective directions, you can "draw your view" / "reposition the nested views in case of activity or view-group" at corresponding location.
An example of how to redraw can be found in any game-example like LunarLander in Android at http://developer.android.com/resources/samples/LunarLander/src/com/example/android/lunarlander/LunarView.html