开发者

Android animation while switching imageview resource

开发者 https://www.devze.com 2023-02-04 00:15 出处:网络
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).

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(Anim开发者_如何学JAVAationUtils.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.


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().


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号