Android Sliding effect Basics (iii) Gallery image set browsing

Source: Internet
Author: User

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;     
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.