对于ObjectAnimator的简单实用

来源:互联网 发布:淘宝网小女孩连衣裙 编辑:程序博客网 时间:2024/06/05 21:54

ObjectAnimator可以简单实现所有动画(透明度,移动,旋转,缩放)

ObjectAnimator的第一个参数是控制的对象比如textview,第二个参数是你要实现的效果(alpha,translate,rotationX,rotationY,backgroundColor等),第三个是效果后边可以加很多参数,效果一次实现

ObjectAnimator oa=ObjectAnimator.ofFloat(tv_text,"alpha",1,0,1,0,1,0,1);        oa.setDuration(3000);//        oa.setRepeatCount(-1);//设置动画重复次数,这里-1代表无限        oa.start();


改变字体颜色,从一个颜色过度到另一个颜色,使用动画  很好的过度

int colorC = Color.parseColor("#333333");int colorD = Color.parseColor("#ffffff");ValueAnimator colorAnim1 = ObjectAnimator.ofInt(tv_title, "textColor", colorC, colorD);colorAnim1.setDuration(timer);colorAnim1.setEvaluator(new ArgbEvaluator());colorAnim1.start();

一个图标过度另一个图标

Drawable return_left_hei = getResources().getDrawable(R.mipmap.return_left_hei);Drawable return_left = getResources().getDrawable(R.mipmap.return_left);TransitionDrawable td1 = new TransitionDrawable(new Drawable[]{return_left_hei, return_left});iv_inforeturn.setBackgroundDrawable(td1);td1.startTransition(timer);

一个大背景颜色过度到另一个大背景颜色

int colorA = Color.parseColor("#edf6f5");int colorB = Color.parseColor("#00cfa5");ValueAnimator colorAnim = ObjectAnimator.ofInt(rl_zongti, "backgroundColor", colorA, colorB);colorAnim.setDuration(timer);colorAnim.setEvaluator(new ArgbEvaluator());colorAnim.start();





原创粉丝点击