補(bǔ)間動畫(TweenAnimaion)四種常用實(shí)現(xiàn)
1. AlphaAnimation(透明)蒙袍,實(shí)現(xiàn)
findViewById(R.id.AlphaAnimation).setOnClickListener {
var alphaAnimation = AlphaAnimation(1.0f, 0.0f)//從全不透明變?yōu)槿该? // 3: 確定持續(xù)時間
alphaAnimation.duration = 2000;
// 4: 確定Interpolator
alphaAnimation.interpolator = LinearInterpolator()
ivSport.startAnimation(alphaAnimation)
}
2.RotateAnimation(旋轉(zhuǎn))沽甥,實(shí)現(xiàn)
findViewById(R.id.RotateAnimation).setOnClickListener {
var rotateAnimation = RotateAnimation(0f, 70f)
rotateAnimation.duration = 2000;
rotateAnimation.interpolator = AccelerateDecelerateInterpolator()
ivSport.startAnimation(rotateAnimation)
}
3.ScaleAnimation(放大縮小)動畫實(shí)現(xiàn)
findViewById(R.id.ScaleAnimation).setOnClickListener {
//放大五倍
var scaleAnimation = ScaleAnimation(0f, 5f, 0f, 5f)
scaleAnimation.duration = 2000; //顯示時長
scaleAnimation.interpolator = AccelerateDecelerateInterpolator()//動畫顯示規(guī)律
ivSport.startAnimation(scaleAnimation)
}
4.ScaleAnimation(位移)動畫實(shí)現(xiàn)
findViewById(R.id.TranslateAnimation).setOnClickListener {
var transAnimation = TranslateAnimation(-400f, 0f, 0f, 0f)
transAnimation.duration = 2000;
transAnimation.interpolator = AccelerateDecelerateInterpolator()
ivSport.startAnimation(transAnimation)
}
5.補(bǔ)間動畫組合使用
val mul = findViewById(R.id.MulAnimation);
mul.setOnClickListener {
var scaleAnimation = ScaleAnimation(1f, 0.5f, 1f, 0.5f)
var transAnimation = TranslateAnimation(0f, ivSport.x - mul.width / 2, 0f, mul.y - ivSport.y + mul.height)
var alphaAnimation = AlphaAnimation(1.0f, 0.0f)//從全不透明變?yōu)槿该? ivSport.startAnimation(alphaAnimation)
val aniSet = AnimationSet(false)
aniSet.duration=2000
aniSet.interpolator= LinearInterpolator()
aniSet.addAnimation(scaleAnimation)
aniSet.addAnimation(transAnimation)
aniSet.addAnimation(alphaAnimation)
ivSport.startAnimation(aniSet)
}