Android ValueAnimator属性动画ObjectAnimator使View颜色渐变,Kotlin
设置背景颜色渐变:
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()
}
开始:
中间:
结束:
https://zhangphil.blog.csdn.net/article/details/134955282https://zhangphil.blog.csdn.net/article/details/134955282