java - 为什么不是我的所有按钮都在 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);
}
解决方案
那是因为您的按钮可能不在您的视图前面,导致它们不可点击。对每个不可点击的按钮使用它
yourButton.bringToFront();
推荐阅读
- android - 如何在 Android Q 中请求外部文件访问权限?
- java - 如何从 src 文件夹调用测试类并使用 maven 构建
- google-assistant-sdk - 协议缓冲区通过 HTTP 调用 Google EmbeddedAssistant API 时频繁返回 HTTP 错误代码 502
- python - 尝试使用 pyoai 连接到 OAI 提供程序时如何修复 python 中的 HTTP 错误 404
- python - 使用 python 和烧瓶的多个 SQL 查询
- java - Docusign java 集成出现错误“http://java.sun.com/jsp/jstl/core 无法解决”
- firebase - 使用 Firebase 多个站点和 Firebase 身份验证,是否可以在一个站点上登录并在另一个站点上保持身份验证?
- php - 如何制作这样的数组
- javascript - 阻止具有源“file://”的框架访问跨域框架
- java - Firebase - 检查 uid 子值是否在 Posts 节点中匹配,如果匹配,则将所有得分值相加并存储在 String 变量中