Android Development Series (22): Features and usage of Adapterviewflipper

Source: Internet
Author: User

Adapterviewflipper inherits the Adapterviewanimator, which displays a view component that can be showprevious () and Shownext () The method control component displays the previous, next component.


XML attributes:

Android:animatefirstview: Sets whether animations are used when the first view of the component is displayed

android:inanimation: Set the animation used when the component is displayed

Android:loopviews: sets whether to automatically "turn head" to the first component after looping to the last component

android:outanimation: set Animation used when component is hidden

Android:autostart: set to show whether the component is AutoPlay

android:flipinterval: Set the time interval for autoplay


These are some of the attributes of this XML.

Below, we have a concrete example to illustrate its function


First, we create a new Android project, we first edit the following Main.xml file:

<span style= "FONT-SIZE:14PX;" ><?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=" android:layout_alignparenttop= "true"/><button android:layout_width= " Wrap_content "android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "Android:layout_ Alignparentleft= "true" android:onclick= "prev" android:text= "previous"/><button android:layout_width= "Wrap_ Content "android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "Android:layout_ Centerhorizontal= "true" android:onclick= "Next" android:text= "Next"/><button android:layout_width= "Wrap_ Content "android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "Android:layout_ Alignparentright= "true" Androidoid:onclick= "Auto" android:text= "AutoPlay"/></relativelayout></span> 
as you can see, there are four components on top, one adapterviewflipper and three buttons, each representing the previous, next, AutoPlay

and set a click event for three buttons


Next we start editing Adapterviewflippertest.java:

<span style= "FONT-SIZE:14PX;" >package org.crazyit.ui;import android.os.bundle;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;import Android.app.activity;public class Adapterviewflippertest extends Activity{int [] Imageids = new Int[]{r.drawable.shuangzi, R.DRAWABLE.SHUANGYU,R.DRAWABLE.CHUNV, R.drawable.tiancheng, R.drawable.tianxie,r.drawable.sheshou, R.drawable.juxie, R.drawable.shuiping,r.drawable.shizi, R.drawable.baiyang , R.drawable.jinniu,r.drawable.mojie}; Adapterviewflipper flipper; @Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.main); flipper = (Adapterviewflipper) Findviewbyid (R.id.flipper);// Creates a Baseadapter object that is responsible for providing the list item displayed by Gallery Baseadapter adapter = new Baseadapter () {@Overridepublic int getcount () {return Imageids.length;} @Overridepublic Object GetItem (int position) {return position;} @Overridepublic long Getitemid (int position) {return position;} The return view of the method is represented by each list item @overridepublic view GetView (int position, view Convertview, ViewGroup parent) {// Create a Imageviewimageview ImageView = new ImageView (adapterviewflippertest.this); Imageview.setimageresource (imageids[ Position]);//Set ImageView scale type Imageview.setscaletype (ImageView.ScaleType.FIT_XY);// Set layout parameters for ImageView imageview.setlayoutparams (new Layoutparams (Layoutparams.match_parent, layoutparams.match_parent) ); return imageView;}; Flipper.setadapter (adapter);} public void prev (View source) {//Displays the previous component flipper.showprevious ();//Stops AutoPlay flipper.stopflipping ();} public void Next (View source) {//Displays the next component. Flipper.shownext ();//Stop AutoPlay flipper.stopflipping ();} public void Auto (View source) {//Start AutoPlay flipper.startflipping ();}} </span>


with these, we can set out some of the features of the app to play the picture.


As follows:




Android Development Series (22): Features and usage of Adapterviewflipper

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.