Android animation while switching imageview resource

无人久伴 提交于 2019-12-24 00:46:00

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/4689220/android-animation-while-switching-imageview-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!