Android Growth Diary-use Viewflipper to achieve screen switching animation effects

Source: Internet
Author: User

(a) Viewflipper introduction

Android system comes with a multi-page management control, it can implement the sub-interface automatic switch

(ii) added view for Viewflipper

1. Static import: Import directly in Layout file (not recommended * not flexible)

2. Dynamic import: AddView () method

Eg:flipper= (Viewfipper) Findviewbyid (r.id.flipper);

Flipper.addview (Getimageview (r.drawable.pic))

(iii) Common methods of Viewflipper

A>setinanimation: Sets the animation used when the view enters the screen

B>setoutanimation: Sets the animation used when the view exits the screen

C>shownext: Call this function to display the next view inside the Viewflipper

D>showprevious: Call this function to display the previous view inside the Viewflipper

E>setfilpinterval: Set the time interval between view transitions

F>startflipping: Use the time interval set above to start switching all view, the switch loops

G>stopflipping: Stop View Toggle

(iii) Adding gesture swipe for viewflipper

private float StartX; Pre-defined

Public boolean ontouchevent (Motionevent event) {

Add gesture Swipe

Switch (Event.getaction ()) {

Falling Fingers

Case Motionevent. Action_down:

Startx=event.getx ();

break;

Finger swipe

Case Motionevent. action_move:

if (Event.getx ()-startx>100)

{

Swipe right to see previous page

Flipper.setinanimation (This, R.anim. Left_in);

Flipper.setoutanimation (This, R.anim. Left_out);

Flipper.showprevious ();//Show Previous page

}

if (Startx-event.getx () >100)

{

Swipe left to see the next page

Flipper.setinanimation (This, R.anim. Right_in);

Flipper.setoutanimation (This, R.anim. Right_out);

Flipper.shownext ();;/ /Show Next Page

}

break;

Finger away

Case Motionevent. action_up:

break;

default:

break;

}

return Super. Ontouchevent (event);

}

Android Growth Diary-use Viewflipper to achieve screen switching animation effects

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.