基本上,我的代码涉及几张图片,但转换是直截了当的。尝试使用.animation和.animationSet,但它没有改变任何东西,我不知道为什么。
ImageView img;
int[] drawables = {R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5};
int counter = 0;
public void changeImage(){ //switches images
if (counter == 5){
counter = 0;
}
img.setImageResource(drawables[counter]);
counter++;
}
public void animate(){ //supposed to animate transitions
Animation fadeIn = new AlphaAnimation(0, 1);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeIn.setDuration(3000);
fadeOut.setDuration(3000);
fadeIn.setInterpolator(new DecelerateInterpolator()); // i dont know what they do but another
fadeOut.setInterpolator(new AccelerateInterpolator()); // user said it was useful. Could you explain?
AnimationSet set = new AnimationSet(false);
img.setAnimation(set);
}
changeImage();
animate();
如果有一种方法要求将开始和结束图像作为输入,我认为它会变得更酷。 另外在哪里可以找到除淡入和淡出之外的其他类型动画的索引。
N.B。:按钮调用changeImage()和animate()方法.OnClickedAction()