gpt4 book ai didi

android:按钮的按下和未按下状态

转载 作者:行者123 更新时间:2023-11-30 03:12:14 25 4
gpt4 key购买 nike

我正在设计一个游戏,其中有一些导弹(按钮)从屏幕上方落到屏幕底部。在屏幕底部,有 5 个目标(也是按钮)。

游戏很简单,当导弹与下方目标重叠时,导弹和目标都会进行动画。

导弹正在扩展视野。

扩展晚会 View :

导弹行动

           spot.setBackgroundResource(R.anim.animation_explosion); 
alert_progress_icon_giraffe = (AnimationDrawable) spot.getBackground();
alert_progress_icon_giraffe.start();
score ++;

mGame_gala.pressing_animation(a);

Game_gala:

public void pressing_animation(int idd_) 
{
btn_up = ((Button) findViewById(idd_));
btn_up.setBackgroundResource(R.anim.animation_press_button);
alert_pressing_button = (AnimationDrawable) btn_up.getBackground();
alert_pressing_button.start();
}

Animation_press_button.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/pressing_button" android:duration="50"/>
<item android:drawable="@drawable/pressing_button_pressed1" android:duration="50"/>
<item android:drawable="@drawable/pressing_btn1" android:duration="50"/>

</animation-list>

可绘制pressing_btn1.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/pressing_button_pressed1"
android:state_pressed="true" />

<item android:drawable="@drawable/pressing_button" />
</selector>

上述机制:

底部目标,没有导弹重叠在它上面,按下时可以执行按下和未按下的图片。然而,当导弹在目标上方时,此时,2个按钮相互重叠,只有导弹可以执行按下和未按下状态图。所以我实现了上面的方法,当按下导弹时,它会调用 Game_gala 方法来使目标制作按下状态的图形。

问题:

导弹第一次来时,导弹和目标都完美完成了压制效果。而当第二枚导弹击中同一个目标时,只有导弹可以执行自己的动画,目标不会显示“按下”状态图形。

但如果目标被单独按下,即使之前被导弹按下,它也可以完美地显示按下和非按下状态。

如何修改以上内容,使得每当有导弹重复击中同一个目标时,目标将在导弹被按下时显示其按下状态?

简而言之,我想让 2 个重叠的按钮在按下时显示按下状态。

谢谢!

最佳答案

不知道是不是因为btn_up膨胀了,第一次后没有获取到btn_up的id...?

尽管如此,我已经找到了一种使用 Handler 而不是使用 AnimationDrawable 的简单方法,这更加简单并且最终效果相同:

public void pressing_animation(int iddd_) 
{
btn_up = ((Button) findViewById(iddd_));
btn_up.setPressed(true);
final Handler handler3 = new Handler();
handler3.postDelayed(new Runnable()
{
@Override
public void run()
{
btn_up.setPressed(false);
}
}, 50);
}

关于android:按钮的按下和未按下状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20745194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com