Layout->main.xml
<framelayout 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 " android:id= "@+id/root" > <imageview android:id= "@+id/imagea" android:layout_width= "Fill_ Parent " android:layout_height=" fill_parent " android:src=" @drawable/image_a " /> < ImageView android:id= "@+id/imageb" android:layout_width= "fill_parent" android:layout_height= " Fill_parent " android:src=" @drawable/image_b " /></framelayout>
Mainactivity.java
Package Com.jikexueyuan.card2d;import Android.app.activity;import Android.os.bundle;import Android.view.View; Import Android.view.view.onclicklistener;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.scaleanimation;import Android.widget.imageview;public class Mainactivity extends Activity {private ImageView imagea;private ImageView Imageb ;//define animation scaleanimation Ani1 = new Scaleanimation (1, 0, 1, 1, animation.relative_to_parent, 0.5f,animation.relative_to_ PARENT, 0.5f); Scaleanimation ani2 = new Scaleanimation (0, 1, 1, 1, animation.relative_to_parent, 0.5f,animation.relative_to_parent, 0.5f); @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Imagea = (ImageView) Findviewbyid (r.id.imagea); Imageb = (ImageView) Findviewbyid (R.ID.IMAGEB);//default display aimagea.setvisibility (view.visible); imageb.setvisibility (View.INVISIBLE);// Set animation time Ani1.setDuration, Ani2.setduration (700);//Click the interface to display the animation 1this.findviewbyid (r.id.root). Setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View v) {if (imagea.getvisibility () = = view.visible) { Imagea.startanimation (ANI1);} else {imageb.startanimation (ANI1);}}); /Add, after animation 1 is finished, start the animation 2ani1.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {} @Overridepublic void Onanimationrepeat (animation animation) {} @Overridepublic void Onanimationend ( Animation Animation) {if (imagea.getvisibility () = = view.visible) {imageb.setvisibility (view.visible); Imagea.setvisibility (view.invisible); imagea.setanimation (null); Imageb.startanimation (ANI2);} else {imagea.setvisibility (view.visible); imageb.setvisibility (view.invisible); imageb.setanimation (null); Imagea.startanimation (ANI2);}});}}
Android Basics: Animated case (picture rollover)