Android动画小结
来源:互联网 发布:淘宝店铺怎么写标题 编辑:程序博客网 时间:2024/05/17 13:42
其中属性动画是3.0开始,矢量动画是5.0可以使用,总结的还有很多不足请指正。
一,平移动画的基本实现方式 1.基本实现,缺点:点击事件不会随着图片的移动而移动
//第一个参数 Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.//第二个参数是设置位置
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.1f,Animation.RELATIVE_TO_SELF,2.0f,
Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f);
translateAnimation.setDuration(5000);
translateAnimation.setFillAfter(true);
translateAnimation.setInterpolator(new BounceInterpolator());
imageView.startAnimation(translateAnimation);
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.1f,Animation.RELATIVE_TO_SELF,2.0f,
Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f);
translateAnimation.setDuration(5000);
translateAnimation.setFillAfter(true);
translateAnimation.setInterpolator(new BounceInterpolator());
imageView.startAnimation(translateAnimation);
2.运用属性动画
ObjectAnimator animator = ObjectAnimator.ofFloat(imageView, "TranslationX", 10, 200).setDuration(5000);
animator.setInterpolator(new BounceInterpolator());
animator.start();
animator.setInterpolator(new BounceInterpolator());
animator.start();
二,旋转动画的实现,
1. RotateAnimation animation = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f, Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(1000);animation.setInterpolator(new AccelerateInterpolator());
imageView.startAnimation(animation);
2. ObjectAnimator.ofFloat(imageView,"Rotation",0,360).setDuration(1000).start();
alpha.setFillAfter(true);
imageView.startAnimation(alpha);
三,透明度动画
1.AlphaAnimation alpha = new AlphaAnimation(1.0f,0.2f);
alpha.setDuration(1000);alpha.setFillAfter(true);
imageView.startAnimation(alpha);
2. ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0.2f).setDuration(1000).start();
四,缩放动画
1. ScaleAnimation scale = new ScaleAnimation(0.5f, 3.0f, 0.5f, 3.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scale.setDuration(1000);
scale.setFillAfter(true);
scale.setInterpolator(new BounceInterpolator());
imageView.startAnimation(scale);
scale.setDuration(1000);
scale.setFillAfter(true);
scale.setInterpolator(new BounceInterpolator());
imageView.startAnimation(scale);
2.
ObjectAnimator.ofFloat(imageView, "scaleX", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "scaleY", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "scaleX", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "scaleY", 0.5F, 3.0f).setDuration(1000).start();
五,动画集合(属性动画)
1. 第一种方式
ObjectAnimator.ofFloat(imageView, "scaleX", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "scaleY", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0.2f).setDuration(1000).start();
第二种方式
PropertyValuesHolder holder1 = PropertyValuesHolder.ofFloat("scaleX", 0.5f, 3.0f);
PropertyValuesHolder holder2 = PropertyValuesHolder.ofFloat("scaleY", 0.5f, 3.0f);
PropertyValuesHolder holder3 = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.2f);
ObjectAnimator.ofFloat(imageView, "scaleX", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "scaleY", 0.5F, 3.0f).setDuration(1000).start();
ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0.2f).setDuration(1000).start();
第二种方式
PropertyValuesHolder holder1 = PropertyValuesHolder.ofFloat("scaleX", 0.5f, 3.0f);
PropertyValuesHolder holder2 = PropertyValuesHolder.ofFloat("scaleY", 0.5f, 3.0f);
PropertyValuesHolder holder3 = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.2f);
ObjectAnimator.ofPropertyValuesHolder(imageView, holder1, holder2, holder3).setDuration(1000).start();
第三种:
public void setScaleAnimBig(View view) {
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(view, "ScaleX", 1.0f, 1.05f);
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(view, "ScaleY", 1.0f, 1.05f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setTarget(view);
animatorSet.playTogether(objectAnimator1);
animatorSet.playTogether(objectAnimator2);
// animatorSet.playSequentially();按照次序来变化
animatorSet.setDuration(300);
animatorSet.start();
}
ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(view, "ScaleX", 1.0f, 1.05f);
ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(view, "ScaleY", 1.0f, 1.05f);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setTarget(view);
animatorSet.playTogether(objectAnimator1);
animatorSet.playTogether(objectAnimator2);
// animatorSet.playSequentially();按照次序来变化
animatorSet.setDuration(300);
animatorSet.start();
}
矢量动画和属性动画的使用:
矢量动画的xml文件
Animator animator = AnimatorInflater.loadAnimator(this, R.anim.rotation1);
animator.setTarget(imageView);
animator.start();
animator.setTarget(imageView);
animator.start();
0 0
- Android 动画学习小结
- Android动画实现小结
- Android-动画小结
- android属性动画小结
- Android动画小结
- 学习Android动画小结
- Android动画小结
- Android动画小结
- Android动画小结
- Android动画小结
- Android动画小结
- Android 属性动画总小结
- Android属性动画个人小结
- 替换Android手机的开机动画小结
- 替换Android手机的开机动画小结
- Android动画学习笔记(三)—基础动画小结
- 动画小结
- Android之动画ViewPager小结(QQ续三)
- ios工程引用,静态库相关
- ASP网站维护1
- C++primer plus第六版课后编程练习答案7.1
- JavaSript模块规范 - AMD规范与CMD规范介绍
- 关于maven管理下的spring工程路径的问题
- Android动画小结
- Problem executing commands on Windows over SSH
- jfreechart
- iOS轮询请求并在图表中动态显示
- Leetcode173: Add and Search Word - Data structure design
- 资源文件包 Bundle
- 开发工具准备
- Windows 系统错代码
- linux驱动程序调试常用方法