First look at the effect:
Layout:
<linearlayout 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:gravi ty= "center" tools:context= ". Mainactivity "> <framelayout android:layout_width=" match_parent "android:layout_height=" Match_paren T "> <imageview android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:layout_gravity=" center "android:src=" @drawable/homepage_disk_button_orange_normal "/> <imageview android:id= "@+id/iv_rotate" android:layout_width= "Wrap_content" Andro id:layout_height= "wrap_content" android:layout_gravity= "center" android:src= "@drawable/homepage_disk _orange_normal "/> <com.example.view.radiationview android:id=" @+id/rv "Android:layout_ Width= "250DP" android:layout_height= "250DP" android:layout_gravity= "center"/> <textview and Roid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "center "Android:text=" SB "android:textcolor=" #ffffff "android:textsize=" 30sp "/> </fra Melayout></linearlayout>
Rotate Animation:
<?xml version= "1.0" encoding= "Utf-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android" android:duration= "12000" android:fromdegrees= "0" android:pivotx= "50%" android:pivoty= "50%" android:startoffset= "0" android:interpolator= "@android: Anim/linear_interpolator" android: "Infinite" android:repeatmode= "restart" android:todegrees= "repeatcount=" />
view with radiation effect:
Package Com.example.view;import Android.content.context;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.os.handler;import Android.util.AttributeSet; Import Android.util.log;import android.view.view;/** * @author ROWANDJJ * * with radiation effect View */public class Radiationview Extend s view{/** * Brush */private paint mpaint = new paint ();/** * color */private int mcolor = 0x3f990e;/** * Transparency */private int Malph A = 60;private Handler Mhandler = null;private static final int message_draw = 0;private static final String TAG = "Radiat Ionview ";p rivate int width;private int height;/** * diffusion velocity */private int speed = 30;/** * Maximum radiation radius */private int Maxradius = 1 00;private int centerx;private int centery;/** * Minimum radius */private int minradius = 70;/** * Current radius */private int radius = Minra Dius;private Boolean isstarted = False;public Radiationview (context context) {super (context); init ();} Public Radiationview (context context, AttributeSet Attrs) {Super (context, attrs, 0);It ();} public void Startradiate () {isstarted = True;mhandler.sendemptymessage (Message_draw);} private void Init () {mpaint = new Paint (); mpaint.setstrokewidth (1);//must first set color, then set Alphampaint.setcolor (Mcolor); Mpaint.setalpha (malpha); mhandler = new Handler () {public void Handlemessage (Android.os.Message msg) {if (Msg.what = = Message_draw) {invalidate (); if (isstarted) {sendemptymessagedelayed (message_draw,speed);}}};} @Overrideprotected void OnLayout (Boolean changed, int left, int top, int. Right,int bottom) {super.onlayout (changed, left, T OP, right, bottom); width = this.getwidth (); height = this.getheight (); if (width <= 0 | | height<=0) {throw new Runtimeex Ception ("size illegal");} Center point centerx = WIDTH/2; CenterY = height/2;//maximum radiation radius Maxradius = (width > height)? HEIGHT/2: WIDTH/2; LOG.I (TAG, "MAX" +maxradius), if (Maxradius <) {throw new RuntimeException ("size too small");}} @Overrideprotected void OnDraw (canvas canvas) {mpaint.setcolor (Mcolor); Mpaint.setalpha (Malpha); if (radius <= 0) { Return}if (Radius > Maxradius) {radius = Minradius;} Canvas.save (); Canvas.drawcircle (CenterX, CenterY, radius, mpaint); Canvas.restore (); radius + = 1;} @Overrideprotected void Onattachedtowindow () {Super.onattachedtowindow (); This.setlayertype (view.layer_type_ software, null);} public void SetColor (int color) {this.mcolor = color;} public void Setspeed (int.) {this.speed = speed;} public void Setminradius (int radius) {This.minradius = radius;}}
code to invoke:
Package Com.example.animdemo1;import Android.app.activity;import Android.os.bundle;import Android.view.animation.animation;import Android.view.animation.animationutils;import Android.widget.ImageView; Import Com.example.view.radiationview;public class Mainactivity extends activity{private ImageView IV = Null;private Radiationview RV = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); iv = (ImageView) Findviewbyid (r.id.iv_rotate); RV = ( Radiationview) Findviewbyid (R.ID.RV) Rv.setminradius (70);//Radiation radius rv.startradiate ();//start radiation animation Anim = Animationutils.loadanimation (this, r.anim.rotate_circle_anim); Iv.startanimation (anim);//Start animation}}
"Android Notes" imitation Music Security homepage Dynamic effect