zoukankan      html  css  js  c++  java
  • Android属性动画ObjectAnimator的使用1

    版权声明:本文为xing_star原创文章,转载请注明出处!

    本文同步自http://javaexception.com/archives/106

    属性动画ObjectAnimator的使用

    属性动画在Android开发的使用场景很多,这篇只是记录基本的API,用ObjectAnimator这个类实现平移,旋转,缩放,透明度这几个效果。属性动画里面有两个关键的类,ObjectAnimator,ValueAnimator,这篇只讲ObjectAnimator的基本用法。

    平移

    private void translate() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "translationX", -textView.getLeft(), mWidth, 0);
        objectAnimator.setDuration(1500);
        objectAnimator.start();
    }

    旋转

    private void rotate() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "rotation", 0, 360);
        objectAnimator.setDuration(1500);
        objectAnimator.start();
    }

    缩放

    private void scale() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "scaleX", 1f, 3f, 1f);
        ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(textView, "scaleY", 1f, 1.5f, 1f);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(1500);
        animatorSet.playTogether(objectAnimator, objectAnimator2);
        animatorSet.start();
    }

    透明度

    private void alpha() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "alpha", 1f, 0f, 1f);
        objectAnimator.setDuration(1500);
        objectAnimator.start();
    }

    案例

    http://javaexception.com/archives/64 这篇文章中,就有用到属性动画实现view左右切换效果。

    其他资料参考:

    Android 属性动画:这是一篇很详细的 属性动画 总结&攻略

    代码下载地址:

    点击原文,获取源代码下载地址。

  • 相关阅读:
    第三章函数
    基本数据类型
    gulp压缩js
    read/load
    jQuery的类数组对象结构
    立即调用表达式
    npm
    cocos2d.js
    图片上传后压缩 Thinkphp
    判断用户是否在微信中
  • 原文地址:https://www.cnblogs.com/xing-star/p/10934043.html
Copyright © 2011-2022 走看看