How can I make my page slide as the user slides finger on the screen?

前端 未结 7 520
后悔当初
后悔当初 2020-12-04 09:12

How can I make my page slide as the user slides finger on the screen? Any example code?

I just require the same feel as it is on my android g-phone\'s home scre

7条回答
  •  感动是毒
    2020-12-04 09:42

    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

提交回复
热议问题