我有这个开关按钮,当它打开时,调用一个动画方法,设置几个可见的元素。但是当我关闭它时,这些元素仍然可见,尽管是相反的指令。我怎样才能让他们失去同样的逻辑?我是否需要创建另一种方法?谢谢,下面的代码:如何使用动画设置元素不可见?
drum.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
key1.setVisibility(View.VISIBLE);
key1.startAnimation(fadeInAnimation());
key2.setVisibility(View.VISIBLE);
key2.startAnimation(fadeInAnimation());
key3.setVisibility(View.VISIBLE);
key3.startAnimation(fadeInAnimation());
rocking.setLooping(true);
rocking.start();
Toast.makeText(getApplicationContext(), "Rock and Rolling!", Toast.LENGTH_SHORT).show();
} else {
rocking.setLooping(false);
key1.setVisibility(View.INVISIBLE);// These instrucions are ignored...
key2.setVisibility(View.INVISIBLE);
key3.setVisibility(View.INVISIBLE);
Toast.makeText(getApplicationContext(), "Can't keep up? Try the tamborine!", Toast.LENGTH_SHORT).show();
}
}
});
与动漫方法:
private Animation fadeInAnimation() {
Animation animation = new AlphaAnimation(0f, 1.0f);
animation.setDuration(1000);
animation.setFillEnabled(true);
animation.setFillAfter(true);
return animation;
}
工作得很好Swathin,感谢您的帮助! – glassraven
高兴地帮助:) – Swathin