属性动画入门
2016-12-20 19:53
232 查看
直接看代码就能明白,布局文件是一个ImageView和五个按钮。下面就是监听事件。
@OnClick({R.id.btn_translate, R.id.btn_scale, R.id.btn_rotate, R.id.btn_alpha, R.id.btn_set})public void onClick(View view) {ObjectAnimator animator=null;switch (view.getId()) {case R.id.btn_translate://位移animator=ObjectAnimator.ofFloat(imgObjectAnimation,"translationX",0f,200f).setDuration(1000*2);// animator=ObjectAnimator.ofFloat(imgObjectAnimation,"translationY",0f,200f).setDuration(1000*2);// animator=ObjectAnimator.ofFloat(imgObjectAnimation,"X",200f).setDuration(1000*2);// animator=ObjectAnimator.ofFloat(imgObjectAnimation,"Y",200f).setDuration(1000*2);break;case R.id.btn_scale://拉伸animator=ObjectAnimator.ofFloat(imgObjectAnimation,"scaleX",1f,2f).setDuration(1000*2);// animator=ObjectAnimator.ofFloat(imgObjectAnimation,"scaleY",1f,2f).setDuration(1000*2);break;case R.id.btn_rotate://旋转animator=ObjectAnimator.ofFloat(imgObjectAnimation,"rotation",0f,360f).setDuration(1000*2);break;case R.id.btn_alpha://透明度animator=ObjectAnimator.ofFloat(imgObjectAnimation,"alpha",1f,0f).setDuration(1000*2);break;case R.id.btn_set:ObjectAnimator animator1=ObjectAnimator.ofFloat(imgObjectAnimation,"translationX",0f,200f).setDuration(1000*2);ObjectAnimator animator2=ObjectAnimator.ofFloat(imgObjectAnimation,"scaleX",1f,2f).setDuration(1000*2);ObjectAnimator animator3=ObjectAnimator.ofFloat(imgObjectAnimation,"rotation",0f,360f).setDuration(1000*2);ObjectAnimator animator4=ObjectAnimator.ofFloat(imgObjectAnimation,"alpha",1f,0f).setDuration(1000*2);AnimatorSet animatorSet=new AnimatorSet();//同时播放// animatorSet.playTogether(animator1,animator2,animator3,animator4);//顺序播放// animatorSet.playSequentially(animator1,animator2,animator3,animator4);//自由排序// animatorSet.play(animator2).with(animator1).after(animator4);//集合List<Animator> animatorList=new ArrayList<>();animatorList.add(animator1);animatorList.add(animator2);animatorList.add(animator3);animatorList.add(animator4);animatorSet.playSequentially(animatorList);animatorSet.setInterpolator(new LinearInterpolator());animatorSet.start();return;default:break;}animator.start();}
相关文章推荐
- Android基础入门教程——8.4.3 Android动画合集之属性动画-初见
- ObjectAnimator 安卓属性动画简单入门
- 属性动画Property Animation入门
- Property 属性动画入门
- Android属性动画入门介绍
- 关于属性动画入门的博客
- Android基础入门教程——8.4.4 Android动画合集之属性动画-又见
- 属性动画-简单入门
- Android属性动画从入门到精通
- 属性动画入门
- android 属性动画入门
- Android 属性动画基础,入门
- SDL入门教程(四):1、SDL动画的软件渲染(Software Render)
- js入门·循环与判断/利用函数的简单实例/使用对象/列举对象属性的名称
- javascript入门·对象属性方法大总结
- 关于类的入门例子(9): 获取对象的 RTTI 属性与事件的函数
- 动画演示 Delphi 2007 IDE 功能[3] - 修改属性
- JS应用DOM入门:DOM的对象属性
- SDL入门教程(三):3、视频属性信息(VideoInfo)
- [荐]JS入门·对象属性方法大总结