当我单击一个按钮时,我想在 500 毫秒内更改按钮背景图像并做一个简短的动画。我已经做了一个代码,但我看不到结果,动画还可以,但点击的图像按钮没有出现。
默认按钮图像是“boutton_a.png”单击的按钮图像是“button_a_ok.png”
这是 onclick 按钮代码:
if (Button04.getText().equals(Reponse)){
Button01.setBackgroundResource(R.drawable.boutton_a_ok);
AnimationSet set=new AnimationSet(true);
Animation animation=new TranslateAnimation(Animation.RELATIVE_TO_SELF,10,Animation.RELATIVE_TO_SELF,10);
animation.setDuration(100);
set.addAnimation(animation);
Button01.startAnimation(set);
}else{
Button01.setBackgroundResource(R.drawable.boutton_a_nok);
AnimationSet set=new AnimationSet(true);
Animation animation=new TranslateAnimation(Animation.RELATIVE_TO_SELF,10,Animation.RELATIVE_TO_SELF,10);
animation.setDuration(100);
set.addAnimation(animation);
Button04.startAnimation(set);
}
我能怎么做 ?
编辑:我已经发布了所有代码,因为有 2 个不同的背景资源