The last issue of the use of Expandablelistview, you have mastered it? This issue begins with the study of the use of adapterviewfilpper.
I. Understanding Adapterviewfilpper
Adapterviewfilpper inherits Adapterviewanimator, which also displays multiple view components provided by Adapter, but it can only display one view component at a time, and the program can pass showprevious () and Shownext () method controls that the component displays the previous, next component.
Adapterviewfilpper can use the fade fade animation effect during multiple view transitions. In addition, you can call the component's startflipping () to control it to "AutoPlay" the next view component.
The XML attributes supported by Adapterviewanimator are as follows:
Android:animatefirstview: Sets whether animation is used when the first view of the display component is displayed.
Android:inanimation: Sets the animation used when the component is displayed.
Android:loopviews: Sets whether to automatically jump to the first component when looping to the last component.
Android:outanimation: Sets the animation used when the component is hidden.
Adapterviewfilpper additional supported XML attributes and related methods are shown in the following table.
Ii. Examples of Adapterviewfilpper
Next, learn how to use adapterviewfilpper using a simple example program.
Continue to use the Listviewsample module of the Widgetsample project to create a adapterview_filpper_layout.xml file in the app/main/res/layout/directory populated with the following code snippet:
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <AdapterviewflipperAndroid:id= "@+id/flipper"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:flipinterval= "the"Android:layout_alignparenttop= "true"/> <ButtonAndroid:id= "@+id/prev_btn"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentleft= "true"Android:text= "Previous"/> <ButtonAndroid:id= "@+id/next_btn"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_centerhorizontal= "true"Android:text= "Next"/> <ButtonAndroid:id= "@+id/auto_btn"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentright= "true"Android:text= "AutoPlay"/></Relativelayout>
Create a Myfilpperadapter class, inherit the Baseadapter class, and rewrite its 4 main methods, with the following code:
PackageCom.jinyu.cqkxzsxy.android.listviewsample.adapter;ImportAndroid.content.Context;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.BaseAdapter;ImportAndroid.widget.ImageView;/*** @ Creator Xin 鱻 * @ description Android 0 Basic primer to Master Series tutorials, welcome to the public number Shareexpert*/ Public classMyfilpperadapterextendsBaseadapter {PrivateContext Mcontext =NULL; Private int[] Mimageids =NULL; PublicMyfilpperadapter (Context context,int[] imageids) { This. Mcontext =context; This. Mimageids =Imageids; } @Override Public intGetCount () {returnmimageids.length; } @Override PublicObject GetItem (intposition) { returnposition; } @Override Public LongGetitemid (intposition) { returnposition; } //The view returned by this method represents each list item@Override PublicView GetView (intposition, View Convertview, ViewGroup parent) {ImageView ImageView=NULL; if(NULL==Convertview) { //Create a ImageViewImageView =NewImageView (Mcontext); //set the scale type of ImageViewImageview.setscaletype (ImageView.ScaleType.FIT_XY); //Set layout parameters for ImageViewImageview.setlayoutparams (Newviewgroup.layoutparams (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) ; Convertview=ImageView; } Else{ImageView=(ImageView) Convertview; } //set up a picture resource for ImageViewImageview.setimageresource (mimageids[position]); returnImageView; }}
Next, provide the adapter for Adapterviewfilpper, using the custom Baseadapter. Create a new Adapterviewfilperactivity.java file and load the new layout file above, with the following code:
Packagecom.jinyu.cqkxzsxy.android.listviewsample;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.widget.AdapterViewFlipper;ImportAndroid.widget.Button;ImportCom.jinyu.cqkxzsxy.android.listviewsample.adapter.MyFilpperAdapter; Public classAdapterviewfilperactivityextendsAppcompatactivityImplementsView.onclicklistener {PrivateAdapterviewflipper Mflipper =NULL; PrivateButton mprevbtn =NULL; PrivateButton mnextbtn =NULL; PrivateButton mautobtn =NULL; Private int[] Mimageids ={r.drawable.image_01,r.drawable.image_02,r.drawable.image_03, r.drawable.image_04,r.drawable.i Mage_05,r.drawable.image_06, r.drawable.image_07,r.drawable.image_08,r.drawable.image_09}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (r.layout.adapterview_filpper_layout); //Get interface ComponentsMflipper =(Adapterviewflipper) Findviewbyid (r.id.flipper); MPREVBTN=(Button) Findviewbyid (R.ID.PREV_BTN); MNEXTBTN=(Button) Findviewbyid (R.ID.NEXT_BTN); MAUTOBTN=(Button) Findviewbyid (R.ID.AUTO_BTN); //set adapter for AdapterviewflipperMyfilpperadapter adapter =NewMyfilpperadapter ( This, Mimageids); Mflipper.setadapter (adapter); //set up a click event listener for three buttonsMprevbtn.setonclicklistener ( This); Mnextbtn.setonclicklistener ( This); Mautobtn.setonclicklistener ( This); } @Override Public voidOnClick (view view) {Switch(View.getid ()) { Caser.id.prev_btn://Show Previous Componentmflipper.showprevious (); //Stop Auto Playmflipper.stopflipping (); Break; Caser.id.next_btn://displays the next component. Mflipper.shownext (); //Stop Auto Playmflipper.stopflipping (); Break; Caser.id.auto_btn://Start auto Playmflipper.startflipping (); Break; default: Break; } }}
The program code above calls Adapterviewflipper's Showprevious (), Shownext () method to control the component's display of the previous, next component, and calls the Startflipping () method to control AutoPlay.
Modify the program start activity, run the program, you can see the interface effect shown.
Click the previous or Next button to toggle the displayed component, click the AutoPlay button, and you will see adapterviewflipper change a picture every 5 seconds, using the fade fade effect when switching pictures.
At this point, the simple use of adapterviewflipper learning is complete, more properties and methods are recommended to practice and master.
Come here today, if you have any questions welcome message to discuss together, also welcome to join the Android 0 Basic introductory Technical discussion group, grow together!
This article copyright for the public Share talent show (Shareexpert)--Xin 鱻 all, if necessary reprint please contact the author authorized, hereby declare!
Past period Summary share:
Android 0 Basics Introduction 1th: Android's past life
Android 0 Basics Section 2nd: Android system Architecture and application components those things
Android 0 Basics Section 3rd: Bring you up to talk about Android development environment
Android 0 Basics 4th: Installing and configuring the JDK correctly Ko fu the first trick
Android 0 Basics 5th: Use ADT bundles to easily meet the goddess
Android 0 Basics 6th: Configuration Optimization SDK Manager, official dating goddess
Android 0 Basics 7th: Take care of Android simulator and start the Sweet journey
Android 0 Basics 8th: HelloWorld, the starting point for my first trip
Android 0 Basics 9th: Android app, no code can be developed
Android 0 Basics Section 10th: Development IDE Big upgrade, finally ushered in Android Studio
Android 0 Basics Introductory Section 11th: Simple steps to take you to fly, run Android Studio project
Android 0 Basics 12th: Get familiar with the Android studio interface and start selling
Android 0 Basics 13th: Android Studio Configuration optimization to create a development tool
Android 0 Basics 14th: Using high-speed genymotion, stepping into the rocket era
Android 0 Basics Section 15th: Mastering the Android Studio project structure, sailing
Android 0 Basics Section 16th: Android User Interface Development overview
Android 0 Basics Section 17th: TextView Properties and Methods Daquan
Android 0 Basics Section 18th: EditText properties and how to use them
Android 0 Basics section 19th: Button usage explained
Android 0 Basics Section 20th: checkbox and RadioButton Usage Daquan
Android 0 Basics Section 21st: ToggleButton and switch usage Daquan
Android 0 Basics Section 22nd: ImageView's properties and methods Daquan
Android 0 Basics Section 23rd: ImageButton and Zoombutton use Daquan
Android 0 Basics Section 24th: Customize view simple to use to create your own controls
Android 0 Basics Section 25th: Simple and most commonly used linearlayout linear layouts
Android 0 Basics Section 26th: Two alignments, layout_gravity and gravity differ greatly
Android 0 Basics section 27th: Using padding and margin correctly
Android 0 Basics Section 28th: Easy to master relativelayout relative layout
Android 0 Basics 29th: Use tablelayout table layouts
Android 0 Basics 30th: Two minutes master Framelayout frame layout
Android 0 Basics Section 31st: absolutelayout absolute Layout with less
Android 0 Basics Section 32nd: New GridLayout Grid layout
Android 0 Basics section 33rd: Android Event Handling overview
Android 0 Basics Section 34th: Listening-based event handling in Android
Android 0 Basics Section 35th: Callback-based event handling in Android
Android 0 Basics Section 36th: Handling of Android system events
Android 0 Basics 37th: First Knowledge ListView
Android 0 Basics 38th: First Knowledge Adapter
Android 0 Basics section 39th: listactivity and custom list items
Android 0 Basics Section 40th: Customizing Arrayadapter
Android 0 Basics Section 41st: Using Simpleadapter
Android 0 Basics Section 42nd: Customizing Baseadapter
Android 0 Basics section 43rd: ListView Optimization and List End-to-end use
Android 0 Basics Section 44th: ListView Data Dynamic Update
Android 0 Basic Getting Started section 45th: Grid view GridView
Android 0 Basics section 46th: List Options Box spinner
Android 0 Basic Getting Started section 47th: AutoComplete text Box Autocompletetextview
Android 0 Basics Section 48th: Collapsible list Expandablelistview
Android 0 Basics section 49th: Adapterviewflipper picture Carousel