Android View animation and androidview Animation

Source: Internet
Author: User

Android View animation and androidview Animation
0. Directory

    • Directory
    • A View background color conversion animation.
    • A displacement change Animation
    • A displacement change Animation
    • Scaling and displacement Animation
    • Scaling and displacement Animation
    • A scaling displacement and transparency animation.

1. A View background color conversion Animation
    private void startBackgroundTranslateAnim(int curColor, int transColor, final View view){        ValueAnimator backgroundColor = ValueAnimator.ofObject(new ArgbEvaluator(),                curColor, transColor);        backgroundColor.addListener(new AnimatorListenerAdapter() {            @Override            public void onAnimationStart(Animator animation) {            }            @Override            public void onAnimationEnd(Animator animation) {            }        });        backgroundColor.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {            @Override            public void onAnimationUpdate(ValueAnimator animation) {                int color = (int) animation.getAnimatedValue();                view.setBackgroundColor(color);            }        });        backgroundColor.setInterpolator(new LinearInterpolator());        backgroundColor.setDuration(500);        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                    public void run() {                    }                })                .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 onAnimationUpdate(ValueAnimator animation) {            }        });        anim.start();
4. scaling and displacement Animation
        final Rect fromRect = ......        final Rect toRect = ......        final float originScaleX = 1.0f;//(float)fromRect.width() / toRect.width();        final float originScaleY = 1.0f;//(float)fromRect.height() / toRect.height();        ValueAnimator trans = ValueAnimator.ofFloat(0, 1);        trans.setInterpolator(new LinearInterpolator());        trans.setDuration(600);        trans.addListener(new AnimatorListener() {            @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(new AnimatorUpdateListener() {            @Override            public void onAnimationUpdate(ValueAnimator animation) {                float percent = (Float)animation.getAnimatedValue();                float toX = (fromRect.left + percent * (toRect.left - fromRect.left));                float toY = (fromRect.top + percent * (toRect.top - fromRect.top));                float toR = (fromRect.right + percent * (toRect.right - fromRect.right));                float toB = (fromRect.bottom + percent * (toRect.bottom - fromRect.bottom));                float scaleX = (float)(toR - toX) / fromRect.width();                float scaleY = (float)(toB - toY) / fromRect.height();                view.setTranslationX(toX-view.getLeft());                view.setTranslationY(toY-view.getTop());                view.setScaleX(scaleX*originScaleX);                view.setScaleY(scaleY*originScaleY);                float alpha = 0 + percent * 1 / (0.8f - 0);        ......            }        });        trans.start();
5. A scaling and displacement Animation
        ObjectAnimator trans = ObjectAnimator.ofFloat(view,View.TRANSLATION_X, newPos);        ObjectAnimator scalex = ObjectAnimator.ofFloat(view, View.SCALE_X, 1.0f, 0.8f);        ObjectAnimator scaley = ObjectAnimator.ofFloat(view, View.SCALE_Y, 1.0f, 0.8f);        AnimatorSet animSet = new AnimatorSet();        animSet.playTogether(scalex, scaley, trans);        animSet.setDuration(duration);        animSet.setInterpolator(new LinearInterpolator());        animSet.addListener(new AnimatorListener() {            @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 scaling, displacement, and transparency Animation
        view.animate().translationX(animTranslationXPx)                .alpha(0.5f)                .setStartDelay(0)                .scaleX(0.8f)                .scaleY(0.8f)                .setUpdateListener(null)                .setInterpolator(new AccelerateDecelerateInterpolator())                .setDuration(1000)                .withEndAction(new Runnable() {                    @Override                    public void run() {                    }                })                .start();

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.