Android Learning-Interface-ui-viewflipper

Source: Internet
Author: User

Viewflipper can add multiple view and can be on one, next, AutoPlay, etc.

3 View, free content

View1.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "First page"android:textappearance= "? Android:attr/textappearancelarge" />    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "button" /></LinearLayout>
View Code

View2.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Second page"android:textappearance= "? Android:attr/textappearancelarge" />    <ZoomcontrolsAndroid:id= "@+id/zoomcontrols1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /></LinearLayout>
View Code

View3.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical" >    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Third page"android:textappearance= "? Android:attr/textappearancelarge" />    <AnalogClockAndroid:id= "@+id/analogclock1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /></LinearLayout>
View Code

Activity_main.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/linearlayout1"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical"Android:background= "#999"    >    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content" >        <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Previous" />        <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Next" />        <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "AutoPlay" />    </LinearLayout>    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content" >        <ViewflipperAndroid:id= "@+id/viewflipper1"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >        </Viewflipper>    </LinearLayout></LinearLayout>
View Code

Mainactivity.java

 Public classMainactivityextendsactivity{//to determine if the finger is left or right    floatX1; floatx2;        Viewflipper ViewFlipper1; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); ViewFlipper1=(Viewflipper) Findviewbyid (r.id.viewflipper1); Button BTN1=(Button) Findviewbyid (R.id.button1); Button btn2=(Button) Findviewbyid (R.id.button2); Button Btn3=(Button) Findviewbyid (R.id.button3); View View1=layoutinflater.from (Getapplicationcontext ()). Inflate (R.layout.view1,NULL); View View2=layoutinflater.from (Getapplicationcontext ()). Inflate (R.layout.view2,NULL); View VIEW3=layoutinflater.from (Getapplicationcontext ()). Inflate (R.LAYOUT.VIEW3,NULL); Viewflipper1.addview (View1,0); Viewflipper1.addview (View2,1); Viewflipper1.addview (VIEW3,2); //the previous oneBtn1.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {pre ();        }        }); //Next OneBtn2.setonclicklistener (NewOnclicklistener () { Public voidOnClick (View v) {next ();                }        }); Btn3.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View v) {viewflipper1.setflipinterval (1000);                            Viewflipper1.startflipping ();        }        }); //Identify gesturesViewflipper1.setontouchlistener (NewOntouchlistener () { Public BooleanOnTouch (View V, motionevent event) {//the coordinates when the finger is pressed                if(event.getaction () = =Motionevent.action_down) {X1=Event.getx (); }                //coordinates when the finger is released                Else if(event.getaction () = =motionevent.action_up) {X2=Event.getx (); //Swipe left                    if(x1-x2>0) {LOG.V ("", "swipe left");                                            Next (); }                    //Swipe Right                    Else if(x2-x1>0) {LOG.V ("", "swipe right");                    Pre (); }                }                return true;      }        }); }            voidNext () {//animating the component display process for ViewswitcherViewflipper1.setinanimation ( This, R.anim.slide_in_right); //animating the component hide process for ViewswitcherViewflipper1.setoutanimation ( This, R.anim.slide_out_left);    Viewflipper1.shownext (); }       voidPre () {//animating the component display process for ViewswitcherViewflipper1.setinanimation ( This, Android.          R.anim.slide_in_left); //animating the component hide process for ViewswitcherViewflipper1.setoutanimation ( This, Android.          R.anim.slide_out_right);            Viewflipper1.showprevious (); }    }
View Code

Android Learning-Interface-ui-viewflipper

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.