我开发了一个管理一副纸牌的应用程序,我需要从这副纸牌中抽出 3 张牌。 问题是只有一个按钮可以点击并制作动画,但其他按钮没有收到点击事件。
//BUTTONS
private void setCardsForPlayer(){
Giocatore giocatoreAttuale = banco.getGiocatoreAttuale();
if(giocatoreAttuale.getCartaByIndex(0)!=null) {
buttonCard1.setImageDrawable(giocatoreAttuale.getCartaByIndex(0).
getImmagine() );
buttonCard1.setOnClickListener(new
CardHandler(this,giocatoreAttuale.getCartaByIndex(0)));
}
else{
buttonCard1.setVisibility(View.INVISIBLE);
}
if(giocatoreAttuale.getCartaByIndex(1)!=null) {
buttonCard2.setImageDrawable(giocatoreAttuale.getCartaByIndex(0).
getImmagine());
buttonCard2.setOnClickListener(new
CardHandler(this,giocatoreAttuale.getCartaByIndex(1)));
}
else{
buttonCard2.setVisibility(View.INVISIBLE);
}
if(giocatoreAttuale.getCartaByIndex(2)!=null) {
buttonCard3.setImageDrawable(giocatoreAttuale.getCartaByIndex(2).
getImmagine());
buttonCard3.setOnClickListener(new
CardHandler(this,giocatoreAttuale.getCartaByIndex(2)));
}
else{
buttonCard3.setVisibility(View.INVISIBLE);
}
}
//ANIMATIONS FUNCTION
private void muoviCarte(){
Animation slideInAnimation = AnimationUtils.loadAnimation(this,
R.anim.move_cards); // THE ANIMATION
buttonCard1.startAnimation(slideInAnimation);
buttonCard2.startAnimation(slideInAnimation);
buttonCard3.startAnimation(slideInAnimation);
}
最佳答案
那是因为您的按钮可能不在您的视野前面,导致它们不可点击。将其用于每个不可点击的按钮
yourButton.bringToFront();
关于java - 为什么我的所有按钮都没有收到 android studio 中单击的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55853282/