yosh
yosh

Reputation: 3305

Android animation while switching imageview resource

Well this is the code I use to animate the view so that old image disappears (black background) and new one slides in from outside (from left to right).

this.imgView.setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right));

this.imgView.setImageResource(imageArray[next]);

How do I make it that old image slides out of the screen before new one shows up. Would be great if both were visible but I guess that would require 2 views to switch, so for now I could stick to one on screen at a time.

Upvotes: 2

Views: 3621

Answers (2)

Imdad Sarkar
Imdad Sarkar

Reputation: 1235

You can do this by using TranslateAnimation. apply the following code and see what happend

  TranslateAnimation left = new TranslateAnimation(-480, 10, 0, 10);
  left.setDuration(2000);

  left.setRepeatCount( 1 );
  view=(ImageView)findViewById( R.id.iv);
  view.startAnimation(left);

Create your own TranslateAnimation and apply accordingly

Upvotes: 1

per_jansson
per_jansson

Reputation: 2189

Use ViewFlipper to switch between two ImageView:s in the same Activity and set a slide animation to the ViewFlipper.

Set correct image resource in the next and previous image view before calling showNext() and showPrevious().

Upvotes: 1

Related Questions