This example describes the Android Viewflipper usage. Share to everyone for your reference, specific as follows:
The effect here is to display the picture one at a time when you slide the phone screen manually, displaying a picture at once
Package com.my.viewflippertest;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.GestureDetector;
Import Android.view.GestureDetector.OnGestureListener;
Import android.view.MotionEvent;
Import Android.widget.TextView;
Import Android.widget.ViewFlipper; public class Viewflippertestactivity extends activity implements Ongesturelistener {private Viewflipper vf;//declares a VIEWFL
Ipper object Private Gesturedetector gd; Private int[] d={//defines a picture set R.drawable.a, r.drawable.b, r.drawable.c, R.DRAWABLE.D, R.DRAWABLE.E, R.DRAWABLE.F
, R.drawable.h, r.drawable.i, r.drawable.g}; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Gd=new Gesturedetector (this); vf= (Viewflipper) This.findviewbyid (R.ID.VF);//Initialize object for (int i=0;i<d.length;i++) {Vf.addview (Addtextview (d[i))); Add interface}} public TextViewAddtextview (int a) {//Add picture to TextView TextView tv=new TextView (this);
Tv.setbackgroundresource (a);
return TV;
//Trigger Contact Event public Boolean ontouchevent (Motionevent event) {return this.gd.onTouchEvent (event); }//Contact event occurs after displaying next picture public boolean onfling (motionevent e1,motionevent e2,float velocityx,float velocityy) {THIS.VF.S
Hownext ();
return true;
@Override public boolean Ondown (Motionevent e) {//TODO auto-generated method stub return false; @Override public void onlongpress (Motionevent e) {//TODO auto-generated method stub} @Override public Boolean o Nscroll (motionevent E1, motionevent E2, float Distancex, float distancey) {//TODO auto-generated method stub return
False @Override public void onshowpress (Motionevent e) {//TODO auto-generated method stub} @Override public Boolean o
Nsingletapup (motionevent e) {//TODO auto-generated method stub return false;
}
}
For more information about Android development interested readers can view the site topics: "Android Development Introduction and Advanced Tutorial"
I hope this article will help you with the Android program.