嗨,动画有问题,实际上我想在 ImageView 更改资源时淡化它。它不起作用,我可以更改资源但没有任何动画。
private void checkX() {
// TODO Auto-generated method stub
switch (x) {
case (1): {
startingAnimation();
xImg.setImageResource(R.drawable.test_uno);
endingAnimation();
break;
}
case (2): {
startingAnimation();
xImg.setImageResource(R.drawable.test_due);
endingAnimation();
break;
}
case (3): {
startingAnimation();
xImg.setImageResource(R.drawable.test_tre);
endingAnimation();
break;
}
case (4): {
startingAnimation();
xImg.setImageResource(R.drawable.test_quattro);
endingAnimation();
break;
}
case (5): {
x = 1;
checkX();
break;
}
case (0): {
x = 4;
checkX();
break;
}
}
}
private void endingAnimation() {
// TODO Auto-generated method stub
ObjectAnimator animation2 = ObjectAnimator.ofFloat(xImg, "alpha", 255);
animation2.setDuration(1000);
animation2.start();
}
private void startingAnimation() {
// TODO Auto-generated method stub
ObjectAnimator animation = ObjectAnimator.ofFloat(xImg, "alpha", 0);
animation.setDuration(1000);
animation.start();
}
每次我按下一个按钮(在 X 上加或减 1)时都会调用 checkX。
我如何使动画和 ImageView 资源都发生变化?