Activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns: tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <viewflipper android:id= "@+id/viewflipper_1" android:layout_width= "Match_parent" android:layout_height= "Match_parent" > <LinearLayout &nBsp;android:id= "@+id/linearlayout_1_1" android:layout_width= " Fill_parent " android:layout_height=" Fill_parent " > <ImageView android:id= "@+id/imageView_1_1" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/kobe0" /> </LinearLayout> <linearlayout android:id= "@+id/ Linearayout_2_2 " &nbsP; android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > < Imageview android:id= "@+id/ Imageview_2_2 " android:layout_width=" Wrap_content " android:layout_height=" Wrap_content " android:src=" @drawable/ Kobe1 " /> </LinearLayout> <LinearLayout android:id= "@+id/linearayout_3_3 " android:layout_width=" "Fill_parent" android:layout_height= "Fill_parent" > <imageview android : id= "@+id/imageview_3_3" android:layout _width= "Wrap_content" android:layout_ height= "Wrap_content" android:src= "@ Drawable/kobe3 " /> </LinearLayout> <LinearLayout android:id= "@+id/linearayout_4_4 " android:layout_width=" Fill_parent " android:layout_height= "Fill_parent" > <ImageView android:id= "@+id/imageview_4_4" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/kobe4" / > </linearlayout> </ Viewflipper> &nbSp; </linearlayout>
Res/anim/in_leftright.xml
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:duration= "android:fromxdelta=" -100%p "android:toxdelta=" 0 " > </translate> </set>
Res/anim/in_rightleft.xml
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:duration= "android:fromxdelta=" 100%p "android:toxdelta=" 0 " > </translate> </set>
Res/anim/out_leftright.xml
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:duration= "android:fromxdelta=" 0 "android:toxdelta=" 100%p " > </translate> </set>
Res/anim/out_rightleft.xml
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:duration= "android:fromxdelta=" 0 "android:toxdelta=" -100%p " > </translate> </set>
Mainactivity
Package com.example.viewflipper;import android. R.integer;import android.app.activity;import android.os.bundle;import android.view.menu;import android.view.menuitem;import android.view.motionevent;import android.widget.viewflipper;public class mainactivity extends activity {private viewflipper viewfilpper;@ Overrideprotected void oncreate (bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); viewfilpper= (Viewflipper) findViewById ( r.id.viewflipper_1);} Override touch Screen Event monitoring method float startx=0.0f;float endx=0.0f; @Overridepublic boolean ontouchevent ( Motionevent event) {// todo auto-generated method stubint action= Event.getaction ();switch (action) {case motionevent.action_down:startx=event.getx (); break;case motionevent.action_up://Swipe Right if (Event.getx ()-startx>10) {Viewfilpper.setinanimatIon (This, r.anim.in_leftright); viewfilpper.setoutanimation (this, r.anim.out_leftright); Viewfilpper.shownext ();} Else if (Startx-event.getx () >10) {viewfilpper.setinanimation (this, r.anim.in_rightleft); Viewfilpper.setoutanimation (This, r.anim.out_rightleft); viewfilpper.showprevious ();} Break;default:break;} Return super.ontouchevent (event);}}
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8B/94/wKiom1hRVeHiJjNTABC_NhHUwJU342.gif-wh_500x0-wm_3 -wmp_4-s_90220252.gif "title=" Jdfw.gif "alt=" Wkiom1hrvehijjntabc_nhhuwju342.gif-wh_50 "/>
This article is from the "matengbing" blog, make sure to keep this source http://matengbing.blog.51cto.com/11395502/1882840
Android's Viewflipper