18

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 :

 runnable = new Runnable() {
           public void run() {
            handler.postDelayed(runnable, 3000);
            imageViewFlipper.setInAnimation(fadeIn);
            imageViewFlipper.setOutAnimation(fadeOut);
            imageViewFlipper.showNext();
           }
          };
          handler = new Handler();
          handler.postDelayed(runnable, 500);
    }

The 2 animated file are not good , they animate very badly . I just need a code to fade out the front image and fade in the next image and do the same for all images inside it.

Could anyone help me out ?

thank you

Pritam
  • 339
  • 3
  • 23
mohsen
  • 451
  • 2
  • 6
  • 15

1 Answers1

3

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
}
Oz Shabat
  • 1,434
  • 17
  • 16