Android View Animation

Source: Internet
Author: User

0. Catalogue

      • Directory
      • A view background color transform animation
      • An animation of displacement change
      • An animation of displacement change
      • A zoom and shift animation
      • A zoom and shift animation
      • A zoom animation for displacement and transparency

1. A view background color transform animation
    Private void Startbackgroundtranslateanim(intCurcolor,intTranscolor,FinalView view) {Valueanimator backgroundcolor = Valueanimator.ofobject (NewArgbevaluator (), Curcolor, Transcolor); Backgroundcolor.addlistener (NewAnimatorlisteneradapter () {@Override             Public void Onanimationstart(Animator animation) {            }@Override             Public void Onanimationend(Animator animation)        {            }        }); Backgroundcolor.addupdatelistener (NewValueanimator.animatorupdatelistener () {@Override             Public void onanimationupdate(Valueanimator animation) {intcolor = (int) Animation.getanimatedvalue ();            View.setbackgroundcolor (color);        }        }); Backgroundcolor.setinterpolator (NewLinearinterpolator ()); Backgroundcolor.setduration ( -);    Backgroundcolor.start (); }
2. A displacement change animation
        view.animate().translationX(animTranslationXPx)                //.alpha(0f)                .setStartDelay(0)                .setUpdateListener(null)                .setInterpolator(new AccelerateDecelerateInterpolator())                .setDuration(1000)                .withEndAction(new Runnable() {                    @Override                    publicvoidrun() {                    }                })                .start();
3. A displacement Change animation
 Objectanimator Anim = Objectanimator.offloat (v,view.translation_x, Newpos);        Anim.setinterpolator (new  linearinterpolator ());        Anim.setduration (500 ); Anim.addlistener (new  animatorlisteneradapter () { @Override  public  void  onanimationend  (Animator animation) {}}); Anim.addupdatelistener (new  Valueanimator.animatorupdatelistener () { @Override  public  void<        /span> onanimationupdate  (Valueanimator animation) {}}); Anim.start (); 
4. A zoom and shift animation
        FinalRect Fromrect = ...FinalRect Torect = ...Final floatOriginscalex =1.0F//(float) fromrect.width ()/Torect.width ();        Final floatOriginscaley =1.0F//(float) fromrect.height ()/Torect.height ();Valueanimator trans = Valueanimator.offloat (0,1); Trans.setinterpolator (NewLinearinterpolator ()); Trans.setduration ( -); Trans.addlistener (NewAnimatorlistener () {@Override             Public void Onanimationstart(Animator animation) { }@Override             Public void onanimationrepeat(Animator animation) { }@Override             Public void Onanimationend(Animator animation) {            }@Override             Public void Onanimationcancel(Animator animation)        {            }        }); Trans.addupdatelistener (NewAnimatorupdatelistener () {@Override             Public void onanimationupdate(Valueanimator animation) {floatPercent = (Float) animation.getanimatedvalue ();floatToX = (Fromrect.left + percent * (torect.left-fromrect.left));floatToY = (fromrect.top + percent * (torect.top-fromrect.top));floatToR = (fromrect.right + percent * (torect.right-fromrect.right));floatToB = (Fromrect.bottom + percent * (torect.bottom-fromrect.bottom));floatScaleX = (float) (Tor-tox)/fromrect.width ();floatScaleY = (float) (Tob-toy)/fromrect.height ();                View.settranslationx (Tox-view.getleft ());                View.settranslationy (Toy-view.gettop ());                View.setscalex (Scalex*originscalex); View.setscaley (Scaley*originscaley);floatAlpha =0+ percent *1/ (0.8F-0);        ......            }        }); Trans.start ();
5. A zoom and shift animation
Objectanimator trans = Objectanimator.offloat (view,view.translation_x, Newpos); Objectanimator ScaleX = objectanimator.offloat (view, view.scale_x,1.0F0.8f); Objectanimator ScaleY = objectanimator.offloat (view, view.scale_y,1.0F0.8f); Animatorset Animset =NewAnimatorset ();        Animset.playtogether (ScaleX, ScaleY, trans);        Animset.setduration (duration); Animset.setinterpolator (NewLinearinterpolator ()); Animset.addlistener (NewAnimatorlistener () {@Override             Public void Onanimationcancel(Animator animation) {            }@Override             Public void Onanimationend(Animator animation) {//do end;}@Override             Public void onanimationrepeat(Animator animation) {            }@Override             Public void Onanimationstart(Animator animation)        {            }        }); Animset.start ();
6. A zoom, shift, and transparency animation
View. Animate(). Translationx(ANIMTRANSLATIONXPX). Alpha(0.5F. Setstartdelay(0). ScaleX(0.8F. ScaleY(0.8F. Setupdatelistener(NULL). Setinterpolator(New Acceleratedecelerateinterpolator ()). Setduration( +). Withendaction(New Runnable () {@Override public void Run () {} }). Start();

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android View Animation

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.