To add gesture monitoring:
1 Gesturedetector detector; // Gesture Listening
View Code
1 New Gesturedetector (Getapplicationcontext (),2 new Mygesturelistener ());
View Code
Gesture listening Specifies the screen slide effect and display image in Onfling:
1 classMygesturelistenerImplementsOngesturelistener {2 //trigger This method when the touch event is pressed3 @Override4 Public BooleanOndown (Motionevent event) {5 return false;6 }7 8 //the user triggers the method by dragging it over the touchscreen9 @OverrideTen Public Booleanonfling (motionevent event1, motionevent Event2, One floatVelocityx,floatvelocityy) { A (GridView) Viewswitcher.getnextview ()). Setadapter (adapter); - if(Event2.getx ()-Event1.getx () >flip_distance) { - if(Screenno > 0) { thescreenno--; - //Add a screen animation toggle effect -Viewswitcher.setinanimation (animations[0]); -Viewswitcher.setinanimation (animations[3]); + viewswitcher.showprevious (); - return true; +}Else { AToast.maketext (Getapplicationcontext (), "No More Pages", at Toast.length_long). Show (); - } -}Else { - if(Screenno < ScreenCount-1) { -screenno++; -Viewswitcher.setinanimation (animations[1]); inViewswitcher.setinanimation (animations[2]); - Viewswitcher.shownext (); to return true; +}Else { -Toast.maketext (Getapplicationcontext (), "No More Pages", the Toast.length_long). Show (); * } $ }Panax Notoginseng return false; - } the + //the user triggers the method on the screen long and on time A @Override the Public voidonlongpress (Motionevent event) { + - } $ $ //trigger This method when the user scrolls on the screen - @Override - Public Booleanonscroll (motionevent event1, motionevent Event2, the floatVelocityx,floatvelocityy) { - return false;Wuyi } the - //This method is triggered when the user presses on the touchscreen and has not moved and released Wu @Override - Public voidonshowpress (motionevent arg0) { About $ } - - //the user taps the event on the touch screen to trigger the method - @Override A Public BooleanOnsingletapup (motionevent arg0) { + return false; the } - $}
View Code
Enter the first interface to show the code:
1 Public voidNext (View v) {2 if(Screenno = =-1) {3screenno++;4 (GridView) Viewswitcher.getnextview ()). Setadapter (adapter);5 Viewswitcher.shownext ();6}Else {7Toast.maketext (Getapplicationcontext (), "No More Pages", Toast.length_long)8 . Show ();9 }Ten}
View Code
Define Baseadapter:
1 PrivateBaseadapter adapter =NewBaseadapter () {2 @Override3 Public LongGetitemid (intposition) {4 returnposition;5 }6 7 @Override8 PublicDataItem GetItem (intposition) {9 returnTotal.get (Screenno * number_per_screen +position);Ten } One A @Override - Public intGetCount () { - if(Screenno = = ScreenCount-1 the&& total.size ()% Number_per_screen! = 0) { - returnTotal.size ()%Number_per_screen; - } - returnNumber_per_screen; + } - + @Override A PublicView GetView (intposition, View Convertview, ViewGroup parent) { atView view =Convertview; - if(Convertview = =NULL) { -View = Layoutinflater.inflate (R.layout.labelicon,NULL); - } -ImageView ImageView =(ImageView) View.findviewbyid (R.id.imageview); - imageview.setimagedrawable (GetItem (position). drawable); inTextView TextView =(TextView) View.findviewbyid (R.id.textview); - Textview.settext (GetItem (position). Dataname); to returnview; + } -};
View Code
Here is just crazy Android handout in Viewswitcher gesture added to do a small demo, I am in the beginner stage, if there is wrong place, please make a lot of corrections!!
Android Handout Second Edition Viewswitcher + gesturedetector Exercises