今天我试着在我的CardView上做眨眼效果...如果我放入backgroundColor就会起作用,但如果我使用strokeColor就不会了。我关注了this tutorial,想让它成为现实,但并不是真的有效……如何更改才能正确地实现此效果?
private fun createBlinkEffect() {
val animator = ObjectAnimator.ofInt(mCardView,
"strokeColor",
ContextCompat.getColor(this, COLOR.WHITE),
ContextCompat.getColor(this, COLOR.RED))
animator.duration = 400
animator.setEvaluator(ArgbEvaluator())
animator.repeatMode = ValueAnimator.REVERSE
animator.repeatCount = ValueAnimator.INFINITE
animator.start()
}这是我的layout_item
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mCardView"
android:layout_width="120dp"
android:layout_height="152dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="4dp"
app:strokeWidth="2dp"
app:strokeColor="@android:color/transparent"
app:cardCornerRadius="12dp">耽误您时间,实在对不起
发布于 2021-08-06 18:07:39
就这样!
private fun createBlinkEffect() {
ObjectAnimator.ofArgb(mCardView,
"strokeColor",
ContextCompat.getColor(this, Color.RED)).apply {
duration = 500
repeatCount = Animation.INFINITE
addUpdateListener { mCardView.invalidate() }
start()
}
}Ps。请记住,使用MaterialCardView代替CardView,并设置默认的strokeWidth和strokeColor
https://stackoverflow.com/questions/68684253
复制相似问题