Android's Viewflipper

Source: Internet
Author: User

First, take a look at its inheritance graph:

Viewanimator directly inherits from Framelayout, where Viewswitcher and Viewflipper are its immediate subclasses.

Today we are going to analyze viewflipper. It can be used to automate the display of images

The effect is as follows:

Code Implementation section:

1, Mainactivity.java

Simple few lines of code, is wayward

public class Mainactivity extends Activity {private viewflipper mviewflipper;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.main);        Mviewflipper = (viewflipper) Findviewbyid (r.id.mviewflipper);             Mviewflipper.setinanimation (this,r.animator.solide_in);  Set the animation mviewflipper.setoutanimation (this, r.animator.solide_out) when the picture is entered        ;//Set the animation        when the picture is cut out Mviewflipper.startflipping ();        }}



2. xml file

Add 3 Sub-view (3 images shown in Viewflipper)

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <viewflipper android:id= "@+id/mviewflipper" android:layout_width= "Match_parent" Andro id:layout_height= "Match_parent" > <imageview android:id= "@+id/iamge1" a            ndroid:layout_height= "Match_parent" android:layout_width= "match_parent" android:src= "@drawable/A"            /> <imageview android:id= "@+id/iamge2" android:layout_height= "Match_parent"             Android:layout_width= "Match_parent" android:src= "@drawable/b"/> <imageview Android:id= "@+id/iamge3" android:layout_height= "Match_parent" android:layout_width= "match _parent "android:src=" @dRawable/c "/> </ViewFlipper></LinearLayout> 


3. Two animated files: Get out of the screen and out of the screen

Enter:

<set xmlns:android= "http://schemas.android.com/apk/res/android" android:interpolator= "@android: anim/ Decelerate_interpolator "  >      <translate          android:duration="          android:fromxdelta= "100%p"          android:toxdelta= "0"/>    <span style= "White-space:pre" ></span> here to go from the right to the screen </set>  


Get out:

<set xmlns:android= "http://schemas.android.com/apk/res/android"      android:interpolator= "@android: anim/ Decelerate_interpolator "     >     <translate  android:duration =" $ "Android:fromxdelta =" 0 "android: Toxdelta = " -100%p"/>    here for <span from the screen style= "font-family:arial, Helvetica, Sans-serif;" > Left to go </span></set>


4, the picture file shown above, can choose their favorite pictures instead, here is not given.

You can also set different view orientation:

Android:fromxdelta= "0" android:toxdelta= " -100%p" disappears to the left

Android:fromxdelta= " -100%p" android:toxdelta= "0" from the left side

Android:fromxdelta= "0" android:toxdelta= "100%p" disappears to the right

Android:fromxdelta= "100%p" android:toxdelta= "0" from the right side

Android's 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.