"Android" itself defines OnDraw-based random animations (not just pan/rotate/zoom/alpha),!

Source: Internet
Author: User

Ideas:

1. Time-based display mapping. Such as: Given the degree, display arc, plus timing, you can have the effect of arc animation

2. Given timing.

A frame drawing for driving animations


Scenario One , based on Objectanimator. When the animation is working, it calls degree the corresponding set function (based on the emission call), i.e. Setdegree.

Objectanimator Ani=objectanimator.ofint (MyView, "degree", 0,300);
Ani.start ();

Note:1> after mixing, the default will be mixed setdegree, resulting in the function can not be found, so the mechanism after the mixture will be invalidated.

The workaround is to prevent this piece of code in 1.proguard (detailed method Baidu) 2. Usage Two

2>objectanimator is only supported after 3.0 and can be used with the Nineoldandroids library, with the same effect.


Scenario Two , still based on Objectanimator. But based on callbacks, such a method is not used to reflect, so the mixed time is still OK

Objectanimator Ani=objectanimator.ofint (MyView, New Prop (), 0,300);
Ani.start ();

Class Prop extends Property<view, integer> {public Prop () {//TODO auto-generated constructor Stubsuper (INTEGER.CLA SS, "KK");} @Overridepublic void Set (View object, Integer value) {//TODO auto-generated Method Stub ((MyView1) object). Setdegree ( value);} @Overridepublic Integer Get (View object) {//TODO auto-generated method Stubreturn null;}};


Programme III , the use of animation to provide timing.

Interpolatedtime is 0~1, which is the percentage of time.

Animation ani=new Animation () {@Overrideprotected void applytransformation (float interpolatedtime,transformation t) {/ /TODO auto-generated method Stubmyview.setdegree ((int) (INTERPOLATEDTIME*300F));}; Ani.setduration (n); Myview.startanimation (ANI);


//===========================================================================


Define your own view, setdegress can change the arc angle:

Private class MyView1 extends ImageView {public int degree = 0;public MyView1 (Context CT) {//TODO auto-generated Construc Tor Stubsuper (CT);} @Overrideprotected void OnDraw (canvas canvas) {//TODO auto-generated method Stubsuper.ondraw (canvas); Rect r = new rect (); Getlocalvisiblerect (R); Canvas.drawarc (new RECTF (R), 0, degree, true, PT);} public void Setdegree (int degree) {this.degree = Degree;invalidate ();}}



Effect:


"Android" itself defines OnDraw-based random animations (not just pan/rotate/zoom/alpha),!

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.