1+ package com.lvfq.code.animation
2+
3+ import android.animation.ValueAnimator
4+ import android.os.Bundle
5+ import android.support.v7.app.AppCompatActivity
6+ import android.util.Log
7+ import android.view.Gravity
8+ import android.view.animation.Interpolator
9+ import android.widget.TextView
10+ import com.lvfq.code.R
11+
12+ /* *
13+ * AnimationActivity
14+ * @author FaQiang on 2018/9/7 下午12:51
15+ * @Github: <a href="https://github.com/lvfaqiang"/>
16+ * @Blog: <a href="http://blog.csdn.net/lv_fq"/>
17+ * @desc :
18+ *
19+ */
20+ class AnimationActivity : AppCompatActivity () {
21+
22+ override fun onCreate (savedInstanceState : Bundle ? ) {
23+ super .onCreate(savedInstanceState)
24+ val textView by lazy {
25+ TextView (this ).apply {
26+ width = 150
27+ height = 150
28+ gravity = Gravity .CENTER
29+ textSize = 14f
30+ setTextColor(resources.getColor(R .color.c_1495eb))
31+ }
32+ }
33+
34+ textView.text = " 0"
35+ setContentView(textView)
36+
37+
38+ val anim = ValueAnimator .ofInt(1 , 2 , 3 ,4 ).setDuration(3000 )
39+ // anim.repeatCount = INFINITE
40+ anim.interpolator = Interpolator {
41+ Log .i(" TAG" , " value: $it " )
42+ it
43+ }
44+
45+ anim.addUpdateListener {
46+ Log .i(" TAG1" , " value: ${it.animatedValue} " )
47+ textView.text = it.animatedValue.toString()
48+ }
49+
50+ anim.start()
51+
52+ textView.setOnClickListener {
53+ if (anim.isStarted) {
54+ anim.cancel()
55+ } else {
56+ anim.start()
57+ }
58+ }
59+
60+ }
61+
62+ }
0 commit comments