在某些设备上的缩放动画期间,有时文本会在 TextView 中消失

问题描述

我想开始每个活动的 onResume 的 textview 的弹跳缩放动画。我注意到有时文本不会在 textview 缩放动画期间显示。我只看到那个文本视图的背景。此错误仅出现在某些设备上:少数小米型号、一台三星、一台 Pixel。在模拟器上运行良好。我正在使用 Animator。我尝试了 Animation 类,但错误仍然存​​在。我该如何解决这个问题?

我的活动代码:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onResume() {
        super.onResume()
        playAnimation()
    }

    private fun playAnimation() {
        val textView = findViewById<TextView>(R.id.textView)
        textView.scaleX = 0f
        textView.scaleY = 0f
        val badgeAnimator = ValueAnimator.ofFloat(0f,1f
        ).apply {
            duration = 800L
            interpolator = BounceInterpolator()
            addUpdateListener { animation ->
                val value = animation.animatedValue as Float
                textView.scaleX = value
                textView.scaleY = value
            }
        }
        val animatorSet = AnimatorSet()
        animatorSet.apply {
            startDelay = 1500L
            play(badgeAnimator)
            start()
        }
    }
}

活动xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textColor="@color/white"
        android:paddingHorizontal="10dp"
        android:background="@drawable/bg_badge_count_v2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

此问题的演示视频。

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)