Adapterviewfilpper of Androidui Components

Source: Internet
Author: User

Package com.gc.adapterviewflipperdemo;/** * Features: auto-play Picture library * @author Android General *//* * 1, Adapterviewfilpper inherits Adapterviewanimator, it also * displays multiple view components provided by adapter, but it can only display one view component at a time *, The Showprevious () and Shownext () methods are used by the program to control the display of the previous and next component of the component. * 2. Adapterviewfilpper can use the fade-out animation effect in multiple view transitions, in addition to calling the component's startflipping () to control it * AutoPlay next view component. * 3, Adapterviewanimator supported XML properties: * Android:animatefirstview-----------Set whether to display the first view of the component using animation * Android: Inanimation----------------Set the animation used when the component is displayed * Android:loopviews------------------set to automatically "turn head" to the first component after looping to the last component * Android : Outanimation---------------Set the animation used when the component is hidden * 4, Adapterviewfillper can support additional XML attributes: * Android: The AutoStart------------------setting shows whether the component plays automatically * Android:flipinterval---------------set the time interval for AutoPlay */import Android.os.bundle;import Android.app.activity;import Android.view.menu;import Android.view.View;import Android.view.viewgroup;import Android.view.viewgroup.layoutparams;import Android.widget.AdapterViewFlipper; Import Android.widget.baseadapter;import Android.widget.ImaGeview;public class Mainactivity extends Activity {private int [] imageids=new int[]{r.drawable.addresslist1, R.DRAWABLE.CONFERENCE2,R.DRAWABLE.DAIBAN3,R.DRAWABLE.EMAIL4,R.DRAWABLE.FILE5,R.DRAWABLE.INFROM6, R.DRAWABLE.ORGANIZATION7,R.DRAWABLE.PUBLICFILE8,R.DRAWABLE.REQUEST9,R.DRAWABLE.SIGN10,R.DRAWABLE.TASK11, R.DRAWABLE.WORK12};p rivate adapterviewflipper flipper; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); flipper= (AdapterViewFlipper) Findviewbyid (r.id.flipper);//Create a Baseadapter object that is responsible for providing the list items displayed by Adapterviewflipper Baseadapter adapter=new Baseadapter () {///The view returned by the method represents each list item @overridepublic view GetView (int position, view Convertview, ViewGroup parent) {// TODO auto-generated Method stub//Create a Imageviewimageview imageview=new ImageView (mainactivity.this); Imageview.setimageresource (Imageids[position]);//Set the zoom type of the ImageView Imageview.setscaletype ( ImageView.ScaleType.FIT_XY);//Set layout parameters for ImageView IMAGEVIEW.SETLAYOUTPArams (New Layoutparams (layoutparams.match_parent,layoutparams.match_parent)); return ImageView;} @Overridepublic long Getitemid (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic Object getItem (int position) {//TODO auto-generated method Stubreturn position;} @Overridepublic int GetCount () {//TODO auto-generated method Stubreturn imageids.length;}}; Flipper.setadapter (adapter);} public void prev (View source) {//Displays the previous component flipper.showprevious ();//Stops AutoPlay flipper.stopflipping ();} public void Next (View source) {//shows the next component Flipper.shownext ();//Stop AutoPlay flipper.stopflipping ();} public void Auto (View source) {//Start AutoPlay flipper.startflipping ();}}
Layout file:
<relativelayout 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 "> <Adap Terviewflipper android:id= "@+id/flipper" android:layout_width= "match_parent" android:layout_height= "match_p   Arent "android:flipinterval=" "android:autostart=" true "android:layout_alignparenttop=" true "/> <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_align Parentbottom= "true" android:layout_alignparentleft= "true" android:onclick= "prev" android:text= "Previous"/&  Gt <button android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_alignPa Rentbottom= "true" android:layout_centerhorizontal= "true" android:onclick= "Next" android:text= "Next"/&G  T <button Android:layout_widtH= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" android:layou T_alignparentright= "true" android:onclick= "Auto" android:text= "Auto Play"/></relativelayout>

Effect


Reprint Please specify source: http://blog.csdn.net/android_jiangjun/article/details/25611263

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.