美文网首页
Android之Kotlin实现TweenAnimaion

Android之Kotlin实现TweenAnimaion

作者: 162f127842fc | 来源:发表于2017-08-23 14:13 被阅读0次

补间动画(TweenAnimaion)四种常用实现

1. AlphaAnimation(透明),实现

findViewById(R.id.AlphaAnimation).setOnClickListener {
            var alphaAnimation = AlphaAnimation(1.0f, 0.0f)//从全不透明变为全透明
            // 3: 确定持续时间
            alphaAnimation.duration = 2000;
            // 4: 确定Interpolator
            alphaAnimation.interpolator = LinearInterpolator()
            ivSport.startAnimation(alphaAnimation)
        }

2.RotateAnimation(旋转),实现

  findViewById(R.id.RotateAnimation).setOnClickListener {
            var rotateAnimation = RotateAnimation(0f, 70f)
            rotateAnimation.duration = 2000;
            rotateAnimation.interpolator = AccelerateDecelerateInterpolator()
            ivSport.startAnimation(rotateAnimation)

        }

3.ScaleAnimation(放大缩小)动画实现

       findViewById(R.id.ScaleAnimation).setOnClickListener {
       //放大五倍
            var scaleAnimation = ScaleAnimation(0f, 5f, 0f, 5f)
            scaleAnimation.duration = 2000;   //显示时长
            scaleAnimation.interpolator = AccelerateDecelerateInterpolator()//动画显示规律
            ivSport.startAnimation(scaleAnimation)
        }

4.ScaleAnimation(位移)动画实现

  findViewById(R.id.TranslateAnimation).setOnClickListener {
            var transAnimation = TranslateAnimation(-400f, 0f, 0f, 0f)
            transAnimation.duration = 2000;
            transAnimation.interpolator = AccelerateDecelerateInterpolator()
            ivSport.startAnimation(transAnimation)

        }

5.补间动画组合使用

  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)//从全不透明变为全透明
            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)
        }

相关文章

网友评论

      本文标题:Android之Kotlin实现TweenAnimaion

      本文链接:https://www.haomeiwen.com/subject/dovddxtx.html