Reproduced please indicate this article from the Big Corn Blog (http://blog.csdn.net/a396901990), thank you for your support!
Implementation ideas
- Draw a small hexagon
- Draw seven small hexagons by location
- Implement a small hexagon display and hide animation
- Play seven small hexagon animations sequentially
Detaileddraw a small hexagon
To draw a hexagon, you only need to know the position and size.
The location uses the center point, and the size uses the distance from the center point to the vertex. Based on these two data, it is possible to find 6 vertex coordinates easily by mathematical method.
After you have calculated the 6 vertex coordinates, you can canvas.drawPath draw a hexagonal:
Paint Mpaint = new paint ();Mpaint. SetColor(Mloadingview. Color);Mpaint. Setstrokewidth(3);Mpaint. Setalpha(0);Cornerpatheffect coreffect = new Cornerpatheffect (Length/corner_path_effect_scale);Mpaint. Setpatheffect(Coreffect);Pointf[] points = gethexagonpoints (centerpoint, length);Path MPath = new Path ();MPath. MoveTo(points[1]. x, points[1]. Y);MPath. LineTo(points[2]. x, points[2]. Y);MPath. LineTo(points[3]. x, points[3]. Y);MPath. LineTo(points[4]. x, points[4]. Y);MPath. LineTo(points[5]. x, points[5]. Y);MPath. LineTo(points[6]. x, points[6]. Y);MPath. Close();Canvas. DrawPath(MPath, Mpaint);
draw seven out of a small hexagon by position
Careful observation reveals that seven small hexagons are actually 6 vertices of a rotated large hexagon + 1 center points, as shown in:
Here is a hole, it is necessary to pay attention to the large hexagonal and small hexagonal edge length problem!
In addition, it is very easy to calculate the center point of 6 small hexagon with pure mathematics.
implement a small hexagon display and hide animation
There are two kinds of animation effects, one is display and one is hidden. This is accomplished using Valueanimator:
Show:
Zoom in and change the transparency first
Valueanimator mshowanimation = Valueanimator.offloat (0,1); Mshowanimation.setduration (animation_duration); Mshowanimation.setinterpolator (NewDecelerateinterpolator ()); Mshowanimation.addupdatelistener (NewValueanimator.animatorupdatelistener () {@Override Public void onanimationupdate(Valueanimator animation) {floatAnimvalue = (float) Animation.getanimatedvalue (); Mscale =0.5F + animvalue/2; Mpaint.setalpha ((int) (Animvalue *255)); Mloadingview.invalidate (); } });
Hide:
Valueanimator mhideanimation = Valueanimator.offloat (1,0); Mhideanimation.setduration (animation_duration); Mhideanimation.setinterpolator (NewDecelerateinterpolator ()); Mhideanimation.addupdatelistener (NewValueanimator.animatorupdatelistener () {@Override Public void onanimationupdate(Valueanimator animation) {floatAnimvalue = (float) Animation.getanimatedvalue (); Mscale =0.5F + animvalue/2; Mpaint.setalpha ((int) (Animvalue *255)); Mloadingview.invalidate (); } });
The hidden animation is actually the display animation upside down, so the animation reverse will be displayed directly.
play seven small hexagon animations sequentially
According to this, we numbered 7 small hexagons as 1,2,3,4,5,6,7. Then one round of animation is:
1 Display, 2, 3 display, 4 display, 5 display, 6 display, 7 show, 1 hidden, 2 hidden, 3 hidden, 4 hidden, 5 hidden, 6 invisible Tibet--7 hidden
Android can use AnimatorSet the playSequentially method to play a set of sequential animation, so we just keep playing this animation sequence is OK!
The code is as follows:
Animatorset mplayanimator = new Animatorset ();arraylist<animator> animators = new arraylist<> ();//AddShow animation for (Overwatchviewitem Item:items) {animators. Add(item. Getshowanimation());} //AddHide animation for (Overwatchviewitem Item:items) {animators. Add(item. Gethideanimation());}//Play animation sequence Mplayanimator. playsequentially(animators);Mplayanimator. Start();
At last
GitHub Address:
Https://github.com/a396901990/LoadingView-OverWatch
Android Parody "Overwatch" Loading animations