?
设置背景颜色渐变:
private var iv: ImageView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
iv = findViewById(R.id.iv)
}
override fun onResume() {
super.onResume()
val colorAnim: ValueAnimator = ObjectAnimator.ofInt(iv, "backgroundColor", Color.parseColor("#FFD800"), Color.TRANSPARENT)
colorAnim.duration = 3000 //经历时长
colorAnim.setEvaluator(android.animation.ArgbEvaluator())
colorAnim.repeatCount = ValueAnimator.INFINITE //无限循环
colorAnim.repeatMode = ValueAnimator.REVERSE
colorAnim.start()
}
?
?
?
开始:
?
?
中间:
?
?
结束:
?
?
?
?