One, Baidu online music merry-go-round effect
On the top of that, when the music is playing, the disc wheel is spinning, like a merry-go-round. Feel good to play ah.
I happen to think of the former play music player, Ah, this can also be done on the phone's music player, so as to replace the progress bar.
The thought, the excitement, so, first draw a circle, and then put the background picture, and then use the animation rotation. While the music is playing,
Starts the animation of a circular picture, pauses the rotation when the music pauses, and stops the animation when the music stops playing, and the picture goes back to the original point.
Second, the effect
Third, the implementation of the Code
(1) mainactivity
<span style= "FONT-SIZE:18PX;"
>public class Mainactivity extends activity {MediaPlayer M1;
ImageView Infooperatingiv;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Infooperatingiv = (ImageView) Findviewbyid (r.id.infooperating);
Button play = (button) Findviewbyid (R.id.play);
Button stop = (button) Findviewbyid (r.id.stop);
Play.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {playmusic ();
}
});
Stop.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {stopmusic ();
}
});
private void Playmusic () {m1 = Mediaplayer.create (this, r.raw.quiet);
M1.start ();
Animation Operatinganim = Animationutils.loadanimation (this, r.anim.tip);
Linearinterpolator lin = new Linearinterpolator (); Operatinganim.setiNterpolator (Lin);
if (Operatinganim!= null) {infooperatingiv.startanimation (Operatinganim); M1.setoncompletionlistener (New Oncompletionlistener () {@Override public void oncompletion (MediaPlayer
MP) {mp.stop ();
Infooperatingiv.clearanimation ();
}
});
private void Stopmusic () {m1.stop ();
Infooperatingiv.clearanimation (); }}</span><span style= "FONT-SIZE:16PT;" > </span>
(2) to draw a circle of controls, this part of the code refers to the user.
<span style= "FONT-SIZE:18PX;"
>public class Roundimageview extends ImageView {private int mborderthickness = 0;
Private context Mcontext;
private int defaultcolor = 0xFFFFFFFF;
If only one of them has a value, draw only a circular border private int mborderoutsidecolor = 0;
private int mborderinsidecolor = 0;
control defaults to long, wide private int defaultwidth = 0;
private int defaultheight = 0;
Public Roundimageview {Super (context);
Mcontext = context;
Public Roundimageview (context, AttributeSet attrs) {Super (context, attrs);
Mcontext = context;
Setcustomattributes (ATTRS);
Public Roundimageview (context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);
Mcontext = context;
Setcustomattributes (ATTRS); } private void Setcustomattributes (AttributeSet attrs) {TypedArray a = Mcontext.obtainstyledattributes (Attrs, R.S
Tyleable.roundedimageview); mborderthickness = A.getdimensionpixelsize (r.styleable. roundedimageview_border_thickness, 0);
Mborderoutsidecolor = A.getcolor (R.styleable.roundedimageview_border_outside_color, DefaultColor);
Mborderinsidecolor = A.getcolor (R.styleable.roundedimageview_border_inside_color, DefaultColor);
} @Override protected void OnDraw (Canvas Canvas) {drawable drawable = getdrawable ();
if (drawable = = null) {return;
} if (getwidth () = = 0 | | getheight () = = 0) {return;
} this.measure (0, 0);
if (drawable.getclass () = = Ninepatchdrawable.class) return;
Bitmap B = ((bitmapdrawable) drawable). Getbitmap ();
Bitmap Bitmap = B.copy (Bitmap.Config.ARGB_8888, true);
if (DefaultWidth = = 0) {defaultwidth = GetWidth ();
} if (DefaultHeight = = 0) {defaultheight = GetHeight (); //Ensure that the image is not resized to change the width and height of the control (ImageView for a wide, high wrap_content layout, but will result in margin)//if (defaultwidth!= 0 && DefaultHeight!= 0) {//Linearlayout.layoutparams params = new LiNearlayout.layoutparams (//DefaultWidth, defaultheight);
Setlayoutparams (params);
int radius = 0; if (mborderinsidecolor!= defaultcolor && mborderoutsidecolor!= defaultcolor) {//define draw two border, outer circle border and inner circle border Radi
US = (DefaultWidth < defaultheight defaultwidth:defaultheight)/2-2 * mborderthickness;
Draw Inner Circle Drawcircleborder (canvas, Radius + MBORDERTHICKNESS/2, mborderinsidecolor);
Draw Outer Circle Drawcircleborder (canvas, radius + mborderthickness + MBORDERTHICKNESS/2, mborderoutsidecolor); else if (mborderinsidecolor!= defaultcolor && mborderoutsidecolor = = DefaultColor) {//define draw a border radius = ( DefaultWidth < DefaultHeight?
defaultwidth:defaultheight)/2-mborderthickness;
Drawcircleborder (canvas, Radius + MBORDERTHICKNESS/2, mborderinsidecolor); else if (Mborderinsidecolor = = DefaultColor && mborderoutsidecolor!= defaultcolor) {//define draw a border radius = ( DefaultWidth <DefaultHeight?
defaultwidth:defaultheight)/2-mborderthickness;
Drawcircleborder (canvas, Radius + MBORDERTHICKNESS/2, mborderoutsidecolor);
else {//no border radius = (DefaultWidth < DefaultHeight defaultwidth:defaultheight)/2;
} Bitmap Roundbitmap = Getcroppedroundbitmap (Bitmap, RADIUS);
Canvas.drawbitmap (Roundbitmap, DEFAULTWIDTH/2-radius, DEFAULTHEIGHT/2-radius, NULL); /** * Get the cropped circular picture * * @param radius * RADIUS * * * * * * Bitmap getcroppedroundbitmap (Bitmap bmp, int
RADIUS) {Bitmap scaledsrcbmp;
int diameter = radius * 2;
In order to prevent the wide-height inequality, resulting in a circular picture deformation, so the intercept rectangle in the middle position of the largest square picture int bmpwidth = Bmp.getwidth ();
int bmpheight = Bmp.getheight ();
int squarewidth = 0, squareheight = 0;
int x = 0, y = 0;
Bitmap Squarebitmap;
if (Bmpheight > Bmpwidth) {//tall in wide squarewidth = Squareheight = Bmpwidth;
x = 0;
y = (bmpheight-bmpwidth)/2; Intercept a square picture squarebitMap = Bitmap.createbitmap (bmp, X, Y, Squarewidth, squareheight);
else if (Bmpheight < bmpwidth) {//leniency to high squarewidth = Squareheight = Bmpheight;
x = (bmpwidth-bmpheight)/2;
y = 0;
Squarebitmap = Bitmap.createbitmap (bmp, X, Y, Squarewidth, squareheight);
else {squarebitmap = bmp; } if (Squarebitmap.getwidth ()!= diameter | | squarebitmap.getheight ()!= diameter) {scaledsrcbmp = Bitmap.cre
Atescaledbitmap (squarebitmap, diameter, diameter, true);
else {scaledsrcbmp = Squarebitmap;
Bitmap output = Bitmap.createbitmap (Scaledsrcbmp.getwidth (), Scaledsrcbmp.getheight (), config.argb_8888);
Canvas Canvas = new Canvas (output);
Paint Paint = new Paint ();
Rect Rect = new Rect (0, 0, scaledsrcbmp.getwidth (), Scaledsrcbmp.getheight ());
Paint.setantialias (TRUE);
Paint.setfilterbitmap (TRUE);
Paint.setdither (TRUE);
Canvas.drawargb (0, 0, 0, 0); Canvas.drawcircle (Scaledsrcbmp.getwiDTH ()/2, Scaledsrcbmp.getheight ()/2, Scaledsrcbmp.getwidth ()/2, paint);
Paint.setxfermode (New Porterduffxfermode (mode.src_in));
Canvas.drawbitmap (scaledsrcbmp, rect, rect, paint);
BMP = NULL;
Squarebitmap = null;
Scaledsrcbmp = null;
return output; /** * Edge Draw Circle/private void Drawcircleborder (Canvas Canvas, int radius, int color) {Paint Paint = new Pa
int ();
/* antialiasing/Paint.setantialias (TRUE);
Paint.setfilterbitmap (TRUE);
Paint.setdither (TRUE);
Paint.setcolor (color);
/* Set paint style for STROKE: Hollow */Paint.setstyle (Paint.Style.STROKE);
/* Set the frame width of paint/paint.setstrokewidth (mborderthickness);
Canvas.drawcircle (DEFAULTWIDTH/2, DEFAULTHEIGHT/2, radius, paint); }}</span><span style= "FONT-SIZE:16PT;"
> </span>
Above is the Android to realize the music effect of the merry-go-round, there is a need for friends can refer to.