Android uses gestures to turn pages

The idea of gesture detection in this program is to hand over the touchevent of activity to gesturedetector. This program uses a viewflipper component, which can use animation to control the switching effect between multiple components.

This example program detects the user's gesture action through gesturedetector, and controls the switching of view components contained in viewflipper according to the gesture action, so as to realize the page turning effect.

activity_ Main.xml layout interface code:

Mainactivity.java logic code:

anim/left_ In.xml Code:

anim/left_ Out.xml Code:

anim/right_ In.xml Code:

anim/right_ Out.xml Code:

The above mainactivity.java logic code only implements the onfling() method of gesturedetector.ongesturelistener. The code of the above program is responsible for the implementation: when the distance between E1. Getx() - E2. Getx() is greater than a specific distance, it can be judged that the user gesture is sliding from right to left. At this time, set the viewflipper to switch to the previous view in an animated manner; When the distance between E2. Getx() - E2. Getx() is greater than a specific distance, it can be judged that the user gesture is sliding from left to right. At this time, set viewflipper to switch to the next view in an animated way -- so as to achieve the so-called "page turning" effect.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>