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