The Android system comes with a gallery view of the application of the image, with a very smooth display of pictures when dragged through the fingers, with good user interaction and experience.
This example uses gallery and custom view to simulate the image browsing effect of a gallery image set. The effect chart is as follows:
1. Basic principle
Implements the Ongesturelistener interface onfling () gesture event in the activity, drawing the draw () picture with a custom View
2. Activity
Activity, registered Mygesture.ontouchevent (event) through Ontouchevent ()
@Override Public
Boolean ontouchevent (Motionevent event) {
switch (event.getaction ()) {
case MOTIONEVENT.ACTION_UP:
flingview.onfling (0); After lifting the finger, reset the sliding distance offsetx = 0 break
;
Return Mygesture.ontouchevent (event);
}
Then we implement the Onscroll () method of the interface Ongesturelistener, pass the sliding parameter to the Handlescroll () member of the Flingview that inherits from the view, get the slide x-axis distance
@Override Public
Boolean onscroll (motionevent E1, motionevent E2, float Distancex, float distancey) {
Flingview.handlescroll ( -1 * (int) Distancex);
return true;
}
Then implement the Onfling () method of the interface Ongesturelistener, pass the sliding parameter to the onfling () member method of the Flingview that inherits from the view, and get the speed of the gesture.
@Override Public
Boolean onfling (motionevent E1, motionevent E2, float Velocityx, float velocityy) {
Flingview.onfling ((int)-Velocityx);
return true;
}