安卓图片动画移动
2015-12-07 22:19
253 查看
1、直线运动:
////1、多个同步 、异步、顺序执行
2、抛物线运动:
////1、多个同步 、异步、顺序执行
ObjectAnimator animator1 = ObjectAnimator.ofFloat(imageView, "translationX", 0F, 360F);// X轴平移旋转 ObjectAnimator animator2 = ObjectAnimator.ofFloat(imageView, "translationY", 0F, 300F);// Y轴平移旋转 ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F);// 360度旋转 AnimatorSet set = new AnimatorSet(); // set.playSequentially(animator1, animator2, animator3);// 分步执行 set.playTogether(animator1, animator2, animator3);// 同步执行 // 属性动画的执行顺序控制 // 先同步执行动画animator2和animator3,然后再执行animator1 /* * set.play(animator3).with(animator1); * * set.play(animator2).after(animator3); */ set.setDuration(1000); set.start();
2、抛物线运动:
// 分300步进行移动动画 final int count = 150; /** * 要start 动画的那张图片的ImageView--------------------(二)抛物线运动 * * @param imageView */ private void startAnimation(final ImageView imageView) { Keyframe[] keyframes = new Keyframe[count]; final float keyStep = 1f / (float) count; float key = keyStep; for (int i = 0; i < count; ++i) { keyframes[i] = Keyframe.ofFloat(key, i + 1); key += keyStep; } PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe( "translationX", keyframes); key = keyStep; for (int i = 0; i < count; ++i) { keyframes[i] = Keyframe.ofFloat(key, -getY(i + 1)); key += keyStep; } PropertyValuesHolder pvhY = PropertyValuesHolder.ofKeyframe( "translationY", keyframes); ObjectAnimator animator3 = ObjectAnimator.ofFloat(imageView, "rotation", 0F, 360F);// 360度旋转 ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(imageView, pvhY, pvhX).setDuration(1500); yxBouncer.setInterpolator(new BounceInterpolator()); AnimatorSet set = new AnimatorSet(); // set.playSequentially(animator1, animator2, animator3);// 分步执行 set.playTogether(yxBouncer, animator3);// 同步执行 set.setDuration(1000); set.start(); } final float a = -1f / 105f; /** * 这里是根据三个坐标点{(0,0),(300,0),(150,300)}计算出来的抛物线方程 * * @param x * @return */ private float getY(float x) { return a * x * x + 4 * x; }
相关文章推荐
- 【莫队算法】[HDU5145]NPY and girls
- 【前缀和思想】cdoj1256昊昊爱运动
- MySQL中innoDB表设计优化
- C指针,C++语言中的指针详解
- MySQL的启动流程及启动时常见错误分析
- 美团O2O排序解决方案——线上篇
- 移动端 图片 相关插件及代码
- linux sdcv命令
- hdoj5311Hidden String
- web集群中常用的session同步解决方案及对比
- python核心编程-递归(阶乘)
- HDU 1059 Dividing(多重背包二进制优化)
- 图片的圆角处理
- dbcp数据库连接超时解决方案
- Java设计模式之简单工厂模式
- 杨小麦OC之旅--多线程
- 内嵌汇编
- 提升网页性能
- LAMP 1.8默认虚拟主机
- 实验四实验报告