我们说我有以下代码:
img1.animate().alpha(.5f).setDuration(300);
我想在动画结束时执行此操作
img1.setImageReasource(R.drawble.img_guitar);
我该怎么做?
答案 0 :(得分:1)
您可以为动画添加侦听器:
imageView.animate().setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
imageView.setImageResource(R.drawable.img_guitar);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
您还可以使用withActionEnd(Runnable)
:
imageView.animate().withEndAction(new Runnable() {
@Override
public void run() {
imageView.setImageResource(R.drawable.img_guitar);
}
})