The implementation of the method is not more introduced first attached source code, I believe we are easy to see understand:
Here in order to make this animation effect can be reused, so inherit the ImageView to implement some methods
Package com.example.loading_drawable;
Import Android.content.Context;
Import android.graphics.drawable.AnimationDrawable;
Import Android.util.AttributeSet;
Import Android.util.Log;
Import Android.view.View;
Import android.view.animation.Animation;
Import Android.widget.ImageView;
public class Myimgview extends ImageView {//Animation layer class private animationdrawable bg_anim;
Public Myimgview {Super (context, NULL); Initview ();}
Public Myimgview (context, AttributeSet attrs) {Super (context, attrs, 0);}
Public Myimgview (context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle); }//Initialize private void Initview () {setbackgroundresource (r.drawable.flash_anim); Bg_anim = (animationdrawable) Getbackgro
und ();
LOG.I ("AAA", "Iniview");
/** * Open Animation effect * * public void Startanim () {if (Bg_anim!= null) {Bg_anim.start ();}}
/** * Stop animation effect/public void Stopanim () {if (Bg_anim!= null && bg_anim.isrunning ()) {bg_anim.stop ();}} /*
* (non-javadoc) * * @see android.widget.imageview#setvisibility (int) When the control is displayed, call to open the animation effect, otherwise * * @Override public void Setvisi Bility (int visibility) {super.setvisibility (visibility); if (visibility = = view.visible) {Startanim ();} else {Stopan
Im ();
}
}
}
Next: Create a new drawable folder under the Res folder, and then create a new Flash_anim.xml file under this folder, as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <animation-list xmlns:android= "http://schemas.android.com/apk/res/" Android "android:oneshot=" false > <item android:drawable= "@drawable/a01_02" android:duration= "/>" < Item android:drawable= "@drawable/a01_04" android:duration= "/> <item android:drawable=" @drawable/a01_06 " android:duration= "/> <item android:drawable=" @drawable/a01_08 "android:duration=" "/> <item Android :d rawable= "@drawable/a01_10" android:duration= "/> <item android:drawable=" @drawable/a01_12 "Android: duration= "/> <item android:drawable=" @drawable/a01_14 "android:duration="/> <item android: drawable= "@drawable/a01_16" android:duration= "/> <item android:drawable=" @drawable/a01_25 "Android: duration= "/> <item android:drawable=" @drawable/a01_26 "android:duration="/> <item android: drawable= "@drawable/a01_27" android:duration= "/> <item android:drawable="/a01_28 "@drawable Android:dur"ation= "/> <item android:drawable=" @drawable/a01_30 "android:duration=" "/> <item" @drawable/a01_31 "android:duration="/> <item android:drawable= "@drawable/a01_32" android:duration= "50" > <item android:drawable= "@drawable/a01_41" android:duration= "/> <item android:drawable=" @drawable A01_42 "android:duration="/> <item android:drawable= "@drawable/a01_43" android:duration= "a"/> android:drawable= "@drawable/a01_44" android:duration= "/> <item android:drawable=" @drawable/a01_45 " android:duration= "/> <item android:drawable=" @drawable/a01_46 "android:duration=" "/> <item Android :d rawable= "@drawable/a01_47" android:duration= "/> <item android:drawable=" @drawable/a01_48 "Android: duration= "/> <item android:drawable=" @drawable/a01_57 "android:duration="/> <item android: drawable= "@drawable/a01_58" android:duration= "/> <item android:drawable=" @drawable/a01_59 "android:duration= "/> <item android:drawable=" @drawable/a01_60 "android:duration="/> <item android: drawable= "@drawable/a01_61" android:duration= "/> <item android:drawable=" @drawable/a01_62 "Android: duration= "/> <item android:drawable=" @drawable/a01_63 "android:duration="/> <item android:
drawable= "@drawable/a01_64" android:duration= "/>" </animation-list>
This is basically done, and the next step is to call the custom main in main, as follows:
Package com.example.loading_drawable;
Import android.app.Activity;
Import Android.os.Bundle;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.LinearLayout;
Import Android.widget.LinearLayout.LayoutParams; /** * @author Administrator mu net Drop-down Refresh Progress Display control * */public class Mainactivity extends activity {@Override protected void oncr
Eate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
LinearLayout rootlayout = new LinearLayout (this);
Rootlayout.setorientation (linearlayout.vertical);
Rootlayout.setlayoutparams (New Linearlayout.layoutparams (LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
Rootlayout.setgravity (Gravity.center);
Button btn = New button (this);
Btn.settext ("show animation");
Final Myimgview Imgview = new Myimgview (mainactivity.this); Imgview.setlayoutparams (New Linearlayout.layoutparams (LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
Imgview.setvisibility (View.gone);
Rootlayout.addview (BTN);
Rootlayout.addview (Imgview);
Setcontentview (rootlayout); Btn.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View arg0) {imgview.setvisibility (Vi ew.
VISIBLE);
}
});
}
}
This is done with custom code layout files, easy layout, plug-in code integration, as mentioned above, the animation is completed, only where necessary to set the Imgview for display, animation will be turned on, hidden animation will be closed.
I hope you can enjoy the details.