gpt4 book ai didi

java - 为什么动画不会将按钮的文本更改为下一次单击?

转载 作者:太空宇宙 更新时间:2023-11-04 10:51:10 26 4
gpt4 key购买 nike

当我第一次按下按钮时,按钮会随着其他按钮一起返回 字母,但当我再次按下时什么也没有发生:
int d = -1; String btnanim = "0";
当我再次按下按钮时如何使其动画?

public void b_b1(View v) {
if (this.btnanim == "AB") {
btn("CD");
return;
}
do {
if (this.btnanim == "CD") {
btn("EF");
return;
}
if (this.btnanim == "EF") {
btn("GH");
return;
}
} while (this.btnanim != "1");
btn("AB");
}

没有动画,文本会改变

void btn(String str) {
this.btnanim = str;
this.timer.schedule(new TimerTask() {
ObjectAnimator anim;
LinearLayout bgroup = (LinearLayout) MainActivity.this.findViewById(R.id.bg);
Button b1 = (Button) MainActivity.this.findViewById(R.id.b1);
Button b2 = (Button) MainActivity.this.findViewById(R.id.b2);

public void run() {
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
MainActivity.this.d += 1;
switch (MainActivity.this.d) {
case 0:
anim = ObjectAnimator.ofFloat(bgroup, "translationX", bgroup.getWidth() * 2);
anim.setDuration(500L).start();
break;
case 5:
anim = ObjectAnimator.ofFloat(bgroup, "translationX", -bgroup.getWidth() * 2);
anim.setDuration(0L).start();
anim = ObjectAnimator.ofFloat(bgroup, "translationX", 0);
anim.setDuration(500L).start();
switch (MainActivity.this.btnanim) {
case "AB":
b1.setText("A");
b2.setText("B");
break;
case "CD":
b1.setText("C");
b2.setText("D");
break;
case "EF":
//Do not repeat the animation this: Changes A and B to C and D then nothing

b1.setText("E");
b2.setText("F");
break;
}
}
}
});
}
}, 0L, 100L);
}


protected void onResume() {
super.onResume();
MainActivity.this.btnanim = "AB";
}
}

最佳答案

我在 void btn(String str) {}

中添加了 this.d = -1;

现在可以正常使用了!

关于java - 为什么动画不会将按钮的文本更改为下一次单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47838191/

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