Hyeyeon blog

[Android] View에 Fade In, Fade Out 애니메이션 적용하기 본문

개발/Android

[Android] View에 Fade In, Fade Out 애니메이션 적용하기

Hyeyeon.P 2020. 11. 23. 19:37
반응형

1. ObjectAnimator 사용을 위해 Java1.8 설정

 // build.gradle(app)
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

2. Fade In (나타나는 효과)

val fadeOut = ObjectAnimator.ofFloat(imageView, "alpha", 0f, 1f)
fadeOut.duration = 1500
fadeOut.start()

3. Fade Out (사라지는 효과)

val fadeOut = ObjectAnimator.ofFloat(imageView, "alpha", 1f, 0f)
fadeOut.duration = 1500
fadeOut.start()

4. 애니메이션 특점 시점의 콜백 받기

fadeOut.addListener(object : Animator.AnimatorListener{
    override fun onAnimationRepeat(animator: Animator?) {
        // TODO       
    }

    override fun onAnimationEnd(animator: Animator?) {
        // TODO 
    }

    override fun onAnimationCancel(animator: Animator?) {
        // TODO         
    }

    override fun onAnimationStart(animator: Animator?) {
        // TODO          
    }
})

728x90
Comments