android- simple fade out and fade in animation for viewflipper

前端 未结 2 1549
一向
一向 2021-02-05 11:05

I\'m new to android and I don\'t know a lot about android animation . I\'ve a viewflipper and I want to animate between images inside it . This is the code :

 r         


        
2条回答
  •  心在旅途
    2021-02-05 11:17

    Simple using Kotlin.

    First, set the animations:

    private fun setAnimations() {
        // in anim
        val inAnim = AlphaAnimation(0f, 1f)
        inAnim.duration = 600
        flipperView.inAnimation = inAnim
    
        // out anim
        val outAnim = AlphaAnimation(1f, 0f)
        outAnim.duration = 600
        flipperView.outAnimation = outAnim
    
    }
    

    And to flip (between two views) just call this function:

    fun onSendClick(view: View) {
        viewFlipper.displayedChild = if(flipperView.displayedChild == 0) 1 else 0
    }
    

提交回复
热议问题