首页 > 解决方案 > 为什么不是我的所有按钮都在 android studio 中收到点击输入?

问题描述

我开发了一个管理一副牌的应用程序,我需要从一副牌中抽出 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);

}

标签: javaandroid

解决方案


那是因为您的按钮可能不在您的视图前面,导致它们不可点击。对每个不可点击的按钮使用它

yourButton.bringToFront();

推荐阅读