本文共 3576 字,大约阅读时间需要 11 分钟。
动画分类:
Activity内容
private ImageView mIvFrame; mIvFrame = (ImageView) this.findViewById(R.id.iv_frame); mIvFrame.setImageResource(R.drawable.frame_list); AnimationDrawable animationDrawable = (AnimationDrawable) mIvFrame.getDrawable(); animationDrawable.start();
(1) Alpha(淡入淡出)
/**补间动画*/ private ImageView mIvTweened; mIvTweened = (ImageView) this.findViewById(R.id.iv_tween); // 淡入淡出 //Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha); mIvTweened.startAnimation(animation);
(2) Translate(位移)
/**补间动画*/ private ImageView mIvTweened; mIvTweened = (ImageView) this.findViewById(R.id.iv_tween); // 淡入淡出 //Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate); mIvTweened.startAnimation(animation);
(3) Scale(缩放大小)
/**补间动画*/ private ImageView mIvTweened; mIvTweened = (ImageView) this.findViewById(R.id.iv_tween); // 淡入淡出 //Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); mIvTweened.startAnimation(animation);
(4) Rotate(旋转)
/**补间动画*/ private ImageView mIvTweened; mIvTweened = (ImageView) this.findViewById(R.id.iv_tween); // 淡入淡出 //Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale); mIvTweened.startAnimation(animation);
(5) 组合动画
/**补间动画*/ private ImageView mIvTweened; mIvTweened = (ImageView) this.findViewById(R.id.iv_tween); // 淡入淡出 //Animation animation = AnimationUtils.loadAnimation(this, R.anim.set); mIvTweened.startAnimation(animation);
(6) 属性解释
pivotX取值 | 含义 |
---|---|
10 | 距离动画所在view自身左边缘10像素 |
10% | 距离动画所在view自身左边缘 的距离是整个view宽度的10% |
10%p | 距离动画所在view父控件左边缘的距离是整个view宽度的10% |
/** * 属性动画 */ private void attrAnimation() { // 淡入淡出 //ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mIvAttr, "alpha", 0.0f, 0.5f, 0.8f, 1.0f); //objectAnimator.setDuration(2000); //objectAnimator.start(); // 位移 /*ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(mIvAttr, "translationX", 100, 300); ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(mIvAttr, "translationY", 100, 300); AnimatorSet animatorSet = new AnimatorSet(); // 同时播放 //animatorSet.playTogether(objectAnimatorX, objectAnimatorY); // 有序播放 animatorSet.playSequentially(objectAnimatorX, objectAnimatorY); animatorSet.setDuration(5000); animatorSet.start();*/ // 缩放 //ObjectAnimator objectAnimatorX = ObjectAnimator.ofFloat(mIvAttr, "scaleX", 0.0f, 1.0f); //ObjectAnimator objectAnimatorY = ObjectAnimator.ofFloat(mIvAttr, "scaleY", 0.0f, 2.0f); //AnimatorSet animatorSet = new AnimatorSet(); //animatorSet.playTogether(objectAnimatorX, objectAnimatorY); //animatorSet.setDuration(5000); //animatorSet.start(); // 旋转 ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mIvAttr, "rotation", 0, 360); objectAnimator.setDuration(2000); objectAnimator.start(); }
转载地址:http://yshna.baihongyu.com/