我正在尝试在另一个ImageView的翻译动画结束时更改ImageButton的图像。我有一个AnimatorListener用于动画,并希望在onAnimationEnd方法中传递ImageButton值,以便我知道要更改哪个ImageButton(在代码中进行一些计算以决定要更改哪个Imagebutton)。我的代码如下。请帮帮我!!!
//animation of an imageview
ObjectAnimator move =ObjectAnimator.ofFloat(myAnimation1,"translationX",20);
//calculating which image to change to for the ImageButton
int id2 = this.getResources().getIdentifier("r" + a[m], "drawable", this.getBaseContext().getPackageName());
//adding animtor listener
move.addListener(new Animator.AnimatorListener(ImageButton,id2) {
@Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
ImageButton.setImageResource(id2); //Not able to use ImageButton and id2...says it has to be final but I don't want it to be final
ImageButton.setClickable(true);
}});
答案 0 :(得分:0)
只需创建另一个最终变量吗?
int id2 = this.getResources().getIdentifier("r" + a[m], "drawable", this.getBaseContext().getPackageName());
final int idFinal = id2;
//adding animtor listener
move.addListener(new Animator.AnimatorListener(ImageButton,id2) {
@Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
ImageButton.setImageResource(idFinal); //Not able to use ImageButton and id2...says it has to be final but I don't want it to be final
ImageButton.setClickable(true);
}});