[Android] mobile guard gesture sliding switch screen

Define gesture recognizer

Get the gesturedetector object of gesture recognizer through new gesturedetector (context, listener). Parameters: context, listener

The anonymous inner class implements the simpleongesturelistener interface of the simple gesture listener and overrides the onfling () sliding method

Four parameters are passed in:

MotionEvent e1 ,MotionEvent e2,veLocityX,veLocityY

E1 is the first point, E2 is the second point, the speed of the x-axis, the speed of the y-axis

When the first point minus the second point is greater than 200, we think it is drawn from right to left, next page

When the second point minus the first point is greater than 200, we think it is drawn from left to right, previous page

Call getrawx() of motionevent object to get the coordinates of X axis

Recognizing gestures using gesture recognizers

Override the ontouchevent () method of activity to get the sliding event of gesture on the interface

Pass in a parameter motionevent object

Call the ontouchevent (event) method of the gesturedetector object, parameter: motionevent object, and pass in the obtained event

Shielding oblique stroke

When the distance between the y-axis coordinates of two points is greater than 100, we think it is drawn obliquely

Call getrawy() of the motionevent object to obtain the coordinates of the y-axis. The difference between the two points takes the absolute value math. Abs(). If it is judged to be greater than 100, it returns true and does not go down

If the simpleongesturelistener class cannot be found, use new gesturedetector. Simpleongesturelistener()

Extract public methods into the base class abstract class basesecactivity. Your own activity only needs to inherit this base class and implement the abstract methods of the previous and next pages to achieve the left-right sliding effect

BaseSecGuideActivity.java

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
分享
二维码
< <上一篇
下一篇>>