Android 4 animation Application 2

Source: Internet
Author: User

I wanted to write down all the animation applications of android4 before, and later I thought I wanted to talk about a set of videos for better learning by programmers, but I had never been able to do so due to time issues, some time ago, I recorded some videos and felt that the recorded results were not satisfactory. I personally felt that my presentation skills were in urgent need of improvement. After recording, I listened to the videos myself, that's bad, but it doesn't matter. I am confident that I can record it well and think that I want to record a free set of fully developed videos for androoid4, from underlying analysis to app launch. To be honest, I have been working for the company for a long time, and I have spent some time writing a few for myself, for example, the interview book for many difficult interviews, the book of life, personalized display and other apps, I have been in the market because of my own design problems. I still cannot tell the difference between business opportunities and preferences, during this period of time, I am still charging the design strictly. I don't know what the IT industry will become when I understand it. I will not talk about anything else, first, paste the previous Animation 2 and Sany, and only paste the core code. I will upload the Demo Video to the Youku: Upload:

This is the core code of cloning:

Package com. JSD. android4.cloning;

Import java. util. arraylist;

Import Android. animation. animatorset;
Import Android. animation. objectanimator;
Import Android. animation. valueanimator;
Import Android. animation. valueanimator. animatorupdatelistener;
Import Android. App. activity;
Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. paint;
Import Android. Graphics. radialgradient;
Import Android. Graphics. shader;
Import Android. Graphics. drawable. shapedrawable;
Import Android. Graphics. drawable. shapes. ovalshape;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. animation. accelerateinterpolator;
Import Android. View. animation. decelerateinterpolator;
Import Android. widget. Button;
Import Android. widget. linearlayout;

Import com. JSD. android4.r;
Import com. JSD. android4.bouncing. shapeholder;

/**
*
* @ Author jankey
*
*/
Public class animcloningactivity extends activity {

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. anim_cloning );
Linearlayout Container = (linearlayout) findviewbyid (R. Id. Container );
Final myanimationview animview = new myanimationview (this );
Container. addview (animview );
Button starter = (button) findviewbyid (R. Id. startbutton );
Starter. setonclicklistener (New View. onclicklistener (){
@ Override
Public void onclick (view v ){
Animview. startanimation ();
}
});
}

Public class myanimationview extends view implements animatorupdatelistener {

Public final arraylist <shapeholder> bballs = new arraylist <shapeholder> ();
Animatorset animation = NULL;
Private float mdensity;

Public myanimationview (context ){
Super (context );
Mdensity = getcontext (). getresources (). getdisplaymetrics (). density;

Shapeholder ball0 = addball (50f, 25f );
Shapeholder ball1 = addball (150f, 25f );
Shapeholder ball2 = addball (250f, 25f );
Shapeholder ball3 = addball (350f, 25f );
Shapeholder ball4 = addball (effecf, 25f );
}

Private void createanimation (){
If (animation = NULL ){
Objectanimator animl = objectanimator. offloat (bils. get (0), "Y", 0f, getheight ()-bils. get (0 ). getheight ()). setduration (500 );
Objectanimator anim2 = animl. Clone ();
Anim2.settarget (bils. Get (1 ));
Animl. addupdatelistener (this );

Shapeholder ball2 = bils. Get (2 );
Objectanimator animdown = objectanimator. offloat (ball2, "Y", 0f, getheight ()-ball2.getheight (). setduration (500 );
Animdown. setinterpolator (New accelerateinterpolator ());
Objectanimator animup = objectanimator. offloat (ball2, "Y", 0f, getheight ()-ball2.getheight (), 0f). setduration (500 );
Animup. setinterpolator (New decelerateinterpolator ());
Animatorset S1 = new animatorset ();
S1.playsequentially (animdown, animup );
Animdown. addupdatelistener (this );
Animup. addupdatelistener (this );
Animatorset S2 = (animatorset) s1.clone ();
S2.settarget (bils. Get (3 ));

Animation = new animatorset ();
Animation. playtogether (animl, anim2, S1 );
Animation. playsequentially (S1, S2 );
}
}

Private shapeholder addball (float X, float y ){
Ovalshape Circle = new ovalshape ();
Circle. Resize (50f * mdensity, 50f * mdensity );
Shapedrawable drawable = new shapedrawable (circle );
Shapeholder = new shapeholder (drawable );
Shapeholder. setx (X-25f );
Shapeholder. sety (Y-25f );
Int Red = (INT) (100 + math. Random () * 155 );
Int Green = (INT) (10 + math. Random () * 155 );
Int Blue = (INT) (100 + math. Random () * 155 );
Int color = 0xff000000 | red <16 | green <8 | blue;
Paint paint = drawable. getpaint ();
Int darkcolor = 0xff000000 | red/4 <16 | green/4 <8 | blue/4;
Radialgradient gradient = new radialgradient (37.5f, 12.5f, 50f, color, darkcolor, shader. tilemode. Clamp );
Paint. setshader (gradient );
Shapeholder. setpaint (paint );
Bils. Add (shapeholder );
Return shapeholder;
}

@ Override
Protected void ondraw (canvas ){
For (INT I = 0; I <bils. Size (); ++ I ){
Shapeholder = bils. Get (I );
Canvas. Save ();
Canvas. Translate (shapeholder. getx (), shapeholder. Gety ());
Shapeholder. getshape (). Draw (canvas );
Canvas. Restore ();
}
}

Public void startanimation (){
Createanimation ();
Animation. Start ();
}

@ Override
Public void onanimationupdate (valueanimator animation ){
Invalidate ();
}
}
}

This is the core code of evalutor:

Package com. JSD. android4.evaluator;

Import java. util. arraylist;

Import Android. animation. objectanimator;
Import Android. animation. typeevaluator;
Import Android. animation. valueanimator;
Import Android. App. activity;
Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. paint;
Import Android. Graphics. radialgradient;
Import Android. Graphics. shader;
Import Android. Graphics. drawable. shapedrawable;
Import Android. Graphics. drawable. shapes. ovalshape;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. Button;
Import Android. widget. linearlayout;

Import com. JSD. android4.r;
Import com. JSD. android4.bouncing. shapeholder;

/**
*
* @ Author jankey
*
*/
Public class customevaluatoracti1_extends activity {

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. evaluator );
Initialized ();
}

Private void initialized (){
Linearlayout Container = (linearlayout) findviewbyid (R. Id. Container );
Final myanimationview animview = new myanimationview (this );
Container. addview (animview );
Button starter = (button) findviewbyid (R. Id. startto );
Starter. setonclicklistener (New View. onclicklistener (){
@ Override
Public void onclick (view v ){
Animview. startanimation ();
}
});
}

Public class xyholder {
Private float MX;
Private float my;

Public xyholder (float X, float y ){
MX = X;
My = y;
}

Public float getx (){
Return MX;
}

Public void setx (float X ){
MX = X;
}

Public float Gety (){
Return my;
}

Public void sety (float y ){
My = y;
}
}

Public class xyevaluator implements typeevaluator {
Public object evaluate (float fraction, object startvalue, object endvalue ){
Xyholder startxy = (xyholder) startvalue;
Xyholder endxy = (xyholder) endvalue;
Return new xyholder (startxy. getx () + fraction * (endxy. getx ()-startxy. getx ()),
Startxy. Gety () + fraction * (endxy. Gety ()-startxy. Gety ()));
}
}

Public class ballxyholder {

Private shapeholder mball;

Public ballxyholder (shapeholder ball ){
Mball = ball;
}

Public void setxy (xyholder ){
Mball. setx (xyholder. getx ());
Mball. sety (xyholder. Gety ());
}

Public xyholder getxy (){
Return new xyholder (mball. getx (), mball. Gety ());
}
}

Public class myanimationview extends view implements valueanimator. animatorupdatelistener {

Public final arraylist <shapeholder> bballs = new arraylist <shapeholder> ();
Valueanimator bounceanim = NULL;
Shapeholder ball = NULL;
Ballxyholder ballholder = NULL;

Public myanimationview (context ){
Super (context );
Ball = createball (25, 25 );
Ballholder = new ballxyholder (ball );
}

Private void createanimation (){
If (bounceanim = NULL ){
Xyholder startxy = new xyholder (0f, 0f );
Xyholder endxy = new xyholder (300f, 800f );
Bounceanim = objectanimator. ofobject (ballholder, "XY ",
New xyevaluator (), endxy );
Bounceanim. setduration (2000 );
Bounceanim. addupdatelistener (this );
}
}

Public void startanimation (){
Createanimation ();
Bounceanim. Start ();
}

Private shapeholder createball (float X, float y ){
Ovalshape Circle = new ovalshape ();
Circle. Resize (50f, 50f );
Shapedrawable drawable = new shapedrawable (circle );
Shapeholder = new shapeholder (drawable );
Shapeholder. setx (X-25f );
Shapeholder. sety (Y-25f );
Int Red = (INT) (math. Random () * 255 );
Int Green = (INT) (math. Random () * 255 );
Int Blue = (INT) (math. Random () * 255 );
Int color = 0xff000000 | red <16 | green <8 | blue;
Paint paint = drawable. getpaint (); // new paint (paint. anti_alias_flag );
Int darkcolor = 0xff000000 | red/4 <16 | green/4 <8 | blue/4;
Radialgradient gradient = new radialgradient (37.5f, 12.5f,
50f, color, darkcolor, shader. tilemode. Clamp );
Paint. setshader (gradient );
Shapeholder. setpaint (paint );
Return shapeholder;
}

@ Override
Protected void ondraw (canvas ){
Canvas. Save ();
Canvas. Translate (ball. getx (), ball. Gety ());
Ball. getshape (). Draw (canvas );
Canvas. Restore ();
}

Public void onanimationupdate (valueanimator animation ){
Invalidate ();
}

}
}

I will not post the res file. It is very simple. It is similar in the past. Below I will paste the running figure:

Well, the above is it. If you are interested, you can modify and integrate the source code to make better results .....

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.