And then egg, Xamarin Android clone Animation menu

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="line-height: 1.5;">net/xamarin, you can turn it off by reading the Diagram.</span></p></p><p><p>Not for proof what, for example only, does not do the actual use, the why and the Egg.</p></p><p><p>Routinely</p></p><p><p></p></p><p><p></p></p><p><p>On Code: Https://github.com/gruan01/Xamarin-Example/tree/master/DiscMenu</p></p><p><p></p></p><p><p>This example is a photo-proof: http://blog.csdn.net/lmj623565791/article/details/43131133</p></p><p><p>But did not do as he did, because that is also the Egg. Who will make the App so fancy?</p></p><p><p></p></p><p><p></p></p><p><p>This example mainly <strong>practices</strong> <span style="color: #800000;">Surfaceview</span> , and the use of <span style="color: #800000;">Animator</span> .</p></p><p><p>, the center of the rolling round head, is made with Surface, although with Animation can do.</p></p><p><p>The Child that pops up is made with Animator.</p></p><p><p></p></p>Surfaceview<p><p>Surfaceview is not interfered with by the UI thread, so its OnDraw method implements the white implementation as Well.</p></p><p><p>It needs to bring a separate thread to update the view Content.</p></p><p><p>To draw, of course, a Canvas is required, which can be obtained:</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">using</span></span>(<span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Canvas =<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Holder.lockcanvas ()) {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(canvas! =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span>. Drawbitmap (canvas,<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Center);</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Drawring (canvas);</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Holder.unlockcanvasandpost (canvas);</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span>}</pre><p><p></p></p><p><p>however, You'd Better Add try. Catch..</p></p><p><p>When you Resume, there will be a little bit of an exception.</p></p><p><p></p></p><p><p>The Lockcanvas () method returns the Canvas that is required for drawing,</p></p><p><p>Unlockcanvasandpost () is to submit the rendered content and release the Canvas.</p></p><p><p></p></p><p><p>In addition, the Isurfaceholdercallback interface must be implemented and registered</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #0000ff;"></span> public <span style="color: #0000ff;">class</span> <span style="color: #000000;">centerview:surfaceview, isurfaceholdercallback, irunnable {</span><span style="color: #008080;">2</span><span style="color: #000000;"> </span> ... <span style="color: #008080;">3</span> <span style="color: #0000ff;"></span> public <span style="color: #0000ff;">int</span> <span style="color: #0000ff;">Base</span> <span style="color: #000000;">(ctx) {</span><span style="color: #008080;">4</span><span style="color: #000000;"> </span> ... <span style="color: #008080;">5</span> <span style="color: #0000ff;"></span>This. Holder.addcallback (<span style="color: #0000ff;"></span>this);</pre></pre><p><p></p></p><p><p></p></p><p><p>Open your own thread in the Isurfaceholdercallback method surfacecreated, and draw in an infinite loop</p></p><pre><pre><span style="color: #008080;">1</span> <span style="color: #0000ff;"></span> public <span style="color: #0000ff;">void</span> <span style="color: #000000;">surfacecreated (isurfaceholder holder) {</span><span style="color: #008080;">2</span> <span style="color: #0000ff;"></span> this <span style="color: #0000ff;">true</span> <span style="color: #000000;">;</span> <span style="color: #008080;">3</span> <span style="color: #0000ff;"></span> this <span style="color: #0000ff;">New</span> Java.Lang.Thread (<span style="color: #0000ff;"></span>this<span style="color: #000000;">);</span> <span style="color: #008080;">4</span> <span style="color: #0000ff;"></span> this <span style="color: #000000;">. Thread.Start ();</span> <span style="color: #008080;">5</span> }</pre></pre><p><p></p></p><p><p></p></p><p><p>Under VS's Android emulator, if not set:</p></p><pre><pre><span style="color: #0000ff;"></span>This. Holder.setformat (format.transparent);</pre></pre><p><p></p></p><p><p>The content of this surfaceview will not be displayed, but everything is performed normally, and there is no problem with the emulator that comes with the Android SDK.</p></p><p><p>The video in the NetEase news client is not displayed on the VS simulator, which I guess is also the Problem.</p></p><p><p></p></p><p><p>Surface is so simple, the rest, on their own brain hole big Open.</p></p><p><p></p></p><p><p></p></p><p><p></p></p>Canvas Related tips 1, Rotating<p><p>As shown in the Ever-rotating avatar, it is the first rotation of the canvas, and then in the drawing</p></p><pre><pre> <span style="color: #0000ff;">Private</span> <span style="color: #0000ff;">void</span> <span style="color: #000000;">drawbitmap (Canvas c, Bitmap bmp) { </span><span style="color: #0000ff;">var</span> sc =<span style="color: #000000;"> c.save (); </span> <span style="color: #0000ff;"></span> this <span style="color: #0000ff;"></span> this <span style="color: #800080;"></span> degree_step +<span style="color: #000000;"> ; </span> <span style="color: #008000;">//</span> <span style="color: #008000;">to rotate first, the paint works.</span> C.rotate (<span style="color: #0000ff;"></span>this<span style="color: #800080;">2</span><span style="color: #800080;">2</span><span style="color: #000000;">); ... </span> <span style="color: #0000ff;">null</span>, rect, paint);</pre></pre><p><p></p></p><p><p>The reverse of the order is not Effective.</p></p><p><p></p></p>2, skeleton<p><p>And the head of the reverse rotation of the green line, in fact, the big round to do the angle gradient, and then with a small circle of the hollow, of course, the canvas is also rotated.</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">construct a ring display area with two circle Path, i.e. knockout inner circle</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>PInner =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Path ();</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span>Pinner.addcircle (cx, cy,<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span>. Bitmapradius + SPACE/<span style="color: #800080;"><span style="color: #800080;">2</span></span><span style="color: #000000;"><span style="color: #000000;">, Path.Direction.Cw);</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>POut =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Path ();</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>Pout.addcircle (cx, cy,<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">. Radius, Path.Direction.Cw);</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;">C.clippath (pOut);</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #000000;"><span style="color: #000000;">C.clippath (pInner, Region.Op.Difference);</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">var color = new color ((int) (DateTime.Now.Ticks% 0xFFFFFFFF));</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">C.drawcolor (color);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">fill the outer circle with an angle gradient</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>g =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">sweepgradient (cx, cy, color.green, color.transparent);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Paint =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Paint ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">Paint. Setshader (g);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>C.drawcircle (cx, cy,<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span>. Radius, paint);</pre><p><p></p></p><p><p>C is canvas,</p></p><p><p>C.clippath (pOut), which restricts the canvas from being drawn only as a closed area of the path of POut.</p></p><p><p>C.clippath (pInner, Region.Op.Difference) excludes the closed area of the PInner from the drawing area of the previous Sentence.</p></p><p><p>Do not reverse the order, the reverse has no effect.</p></p><p><p></p></p>3, supplement: positive and negative two directions<p><p>One Direction is not interesting, two directions is how to do it? It is simple to draw the head to the right angle (x), draw the head to the outside of the circle is used By-x</p></p><p><p></p></p><p><p></p></p>Animator<p><p>Surfaceview does not do interactive control, so the animation of the popup child is made with Animator.</p></p><p><p>Android Animation is divided into many kinds, I do not know, is now learning to sell Just.</p></p><p><p>This is mainly to achieve the child position/size changes, so I used the Objectanimator</p></p><pre><pre><span style="color: #0000ff;">var</span> <span style="color: #800000;">"</span> <span style="color: #800000;">X</span> <span style="color: #800000;">"</span> <span style="color: #000000;">, xs);</span> <span style="color: #0000ff;">var</span> <span style="color: #800000;">"</span> <span style="color: #800000;">Y</span> <span style="color: #800000;">"</span> <span style="color: #000000;">, ys);</span> <span style="color: #0000ff;">var</span> <span style="color: #800000;">"</span> <span style="color: #800000;">ScaleX</span> <span style="color: #800000;">"</span> <span style="color: #000000;">, ss);</span> <span style="color: #0000ff;">var</span> <span style="color: #800000;">"</span> <span style="color: #800000;">ScaleY</span> <span style="color: #800000;">"</span>, ss);</pre></pre><p><p></p></p><p><p>where c is the child view,</p></p><p><p>X, Y, ScaleX, ScaleY You can understand the reflection Of. NET, which uses reflection to update the values of these Properties.</p></p><p><p></p></p>Unfold and retract<p><p>is a two-way reverse process, that is, the starting value and the end value of a swap, you can</p></p><pre><pre><span style="color: #0000ff;">float</span> <span style="color: #0000ff;">New</span> <span style="color: #0000ff;">float</span> [] {cx-<span style="color: #000000;"> hw, l};</span> <span style="color: #0000ff;">float</span> <span style="color: #0000ff;">New</span> <span style="color: #0000ff;">float</span> [] {cy-<span style="color: #000000;"> hy, t};</span> <span style="color: #0000ff;">float</span> <span style="color: #0000ff;">New</span> <span style="color: #0000ff;">float</span> <span style="color: #800080;">0.1f</span> <span style="color: #800080;">1</span> <span style="color: #000000;"> };</span> <span style="color: #0000ff;">if</span> (! <span style="color: #000000;">Expand) { Array.reverse (xs); Array.reverse (ys); Array.reverse (ss);}</span></pre></pre><p><p></p></p><p><p>In the beginning, I want to save these Animator, when the collection of the time, the various Animator. Reverse (), So you can get the inverse animation. But I never get back to the center, so I gave up the Idea.</p></p><p><p></p></p>Jumping Egg mode<p><p>The name I gave it myself was actually interpolator.</p></p><pre><pre><span style="color: #0000ff;">set</span>. Setinterpolator (<span style="color: #0000ff;">new</span> Android.Views.Animations.BounceInterpolator ());</pre></pre><p><p></p></p><p><p>Try a few interpolator, this jumping egg pattern can be expanded at the time, the rightmost child to expand to the specified Point.</p></p><p><p></p></p>Circular arrangement<p><p>I returned to the teacher early math, here with the trigonometric functions, the Pythagorean theorem are baidu, so the table asked Me.</p></p><p><p></p></p><p><p>-----------------------</p></p><p><p>finish, Thank you for watching, please point ...</p></p><p><p>And then egg, Xamarin Android clone Animation menu</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.