[宣传视频] fix: 动画中NPE问题;
This commit is contained in:
@@ -54,22 +54,26 @@ class TurnSignalView : LinearLayout {
|
||||
//根据左右进行显示和隐藏,实际要判断每个来的时间和频度
|
||||
when (directionLight) {
|
||||
Chassis.LightSwitch.LIGHT_LEFT -> { //左转向
|
||||
leftSelectImage.visibility = View.VISIBLE
|
||||
rightSelectImage.visibility = View.GONE
|
||||
rightSelectImage.clearAnimation()
|
||||
setAnimation(leftSelectImage)
|
||||
leftSelectImage?.visibility = View.VISIBLE
|
||||
rightSelectImage?.visibility = View.GONE
|
||||
rightSelectImage?.clearAnimation()
|
||||
leftSelectImage?.also {
|
||||
setAnimation(it)
|
||||
}
|
||||
}
|
||||
Chassis.LightSwitch.LIGHT_RIGHT -> { //右转向
|
||||
leftSelectImage.visibility = View.GONE
|
||||
rightSelectImage.visibility = View.VISIBLE
|
||||
leftSelectImage.clearAnimation()
|
||||
setAnimation(rightSelectImage)
|
||||
leftSelectImage?.visibility = View.GONE
|
||||
rightSelectImage?.visibility = View.VISIBLE
|
||||
leftSelectImage?.clearAnimation()
|
||||
rightSelectImage?.also {
|
||||
setAnimation(it)
|
||||
}
|
||||
}
|
||||
else -> { //消失
|
||||
leftSelectImage.clearAnimation()
|
||||
rightSelectImage.clearAnimation()
|
||||
leftSelectImage.visibility = View.GONE
|
||||
rightSelectImage.visibility = View.GONE
|
||||
leftSelectImage?.clearAnimation()
|
||||
rightSelectImage?.clearAnimation()
|
||||
leftSelectImage?.visibility = View.GONE
|
||||
rightSelectImage?.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,14 +81,18 @@ class TurnSignalView : LinearLayout {
|
||||
|
||||
//实现图片闪烁效果
|
||||
private fun setAnimation(imageView: ImageView) {
|
||||
val animationSet = AnimatorSet()
|
||||
val valueAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1.0f)
|
||||
val valueAnimatorDisappare = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0f)
|
||||
valueAnimator.duration = 1000
|
||||
valueAnimatorDisappare.duration = 800
|
||||
valueAnimator.repeatCount = -1
|
||||
valueAnimatorDisappare.repeatCount = -1
|
||||
animationSet.playTogether(valueAnimatorDisappare, valueAnimator)
|
||||
animationSet.start()
|
||||
try {
|
||||
val animationSet = AnimatorSet()
|
||||
val valueAnimator = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1.0f)
|
||||
val valueAnimatorDisappare = ObjectAnimator.ofFloat(imageView, "alpha", 1.0f, 0f)
|
||||
valueAnimator.duration = 1000
|
||||
valueAnimatorDisappare.duration = 800
|
||||
valueAnimator.repeatCount = -1
|
||||
valueAnimatorDisappare.repeatCount = -1
|
||||
animationSet.playTogether(valueAnimatorDisappare, valueAnimator)
|
||||
animationSet.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user