动画发生之前先查看可见,然后动画发生

时间:2019-03-16 03:20:47

标签: java android animation kotlin

我想在其余所有动画完成后从左侧制作journeyText: TextView的动画。但是journeyText在开始过程中是可见的,然后发生动画。

我已经执行以下操作:

    val animator1 = ObjectAnimator.ofFloat(circularFace, "translationY", 2000f,0f)
    animator1.repeatCount = 0
    animator1.duration = 1000

    val animator2 = ObjectAnimator.ofFloat(happyBdayText, "translationX", -2000f, 0f)
    animator2.repeatCount = 0
    animator2.duration = 1000

    val animator3 = ObjectAnimator.ofFloat(journeyText, "translationX", -2000f, 0f)
    animator3.repeatCount = 0
    animator3.duration = 2000
    animator3.startDelay = 5000

    val set = AnimatorSet()
    set.play(animator1)
    set.play(animator2)
    set.play(animator3)
    set.start()

我尝试设置可见性,但是它不起作用。

1 个答案:

答案 0 :(得分:0)

您可以降低startDelay的值。

package com.example.myapplication

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

class MainActivity : AppCompatActivity() {

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

        val textView = findViewById<TextView>(R.id.text)
        val animator1 = ObjectAnimator.ofFloat(textView, "translationY", 2000f, 0f)
        animator1.repeatCount = 0
        animator1.duration = 1000

        val textTwo = findViewById<TextView>(R.id.texttwo)
        val animator2 = ObjectAnimator.ofFloat(textTwo, "translationX", -2000f, 0f)
        animator2.repeatCount = 0
        animator2.duration = 1000

        val textThree = findViewById<TextView>(R.id.textThree)
        val animator3 = ObjectAnimator.ofFloat(textThree, "translationX", -2000f, 0f)
        animator3.repeatCount = 0
        animator3.duration = 2000
        animator3.startDelay = 1

        val set = AnimatorSet()
        set.play(animator1)
        set.play(animator2)
        set.play(animator3)
        set.start()
    }
}

link