An example of Android viewflipper usage _android

Source: Internet
Author: User
Tags stub

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.

Related Article

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.