Android property-animation 占CPU偏高

//Kotlin code
class MainActivity : AppCompatActivity() {
    val TAG: String = "MAINACTIVITY"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        hello.setText("hahaha")
        //property-animatioin
        val set = AnimatorInflater.loadAnimator(this, R.animator.property_animator)
        if(set is AnimatorSet){
            set.setTarget(hello)
            set.start()
        }
        //View-animation
        image.setBackgroundResource(R.drawable.rocket)
        val ra = image.background
        if(ra is AnimationDrawable)ra.start()
        image2.startAnimation(AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump))
        Log.d(TAG, "onCreate")
    }
}

<set android:ordering="together"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <objectAnimator
        android:propertyName="textColor"
        android:valueFrom="#f00"
        android:valueTo="#fff"
        android:duration="3000"
        android:repeatCount="-1"
        android:repeatMode="reverse"
        />
    <objectAnimator
        android:propertyName="textSize"
        android:valueFrom="14sp"
        android:valueTo="20sp"
        android:duration="3000"
        android:repeatMode="reverse"
        android:repeatCount="-1"
        android:valueType="floatType"
        />
set>

在使用Property-animation时候,用Android profiler检测如图

Android property-animation 占CPU偏高_第1张图片

不使用的时候
Android property-animation 占CPU偏高_第2张图片

你可能感兴趣的:(Android)