(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