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

时间:2017-12-15 18:44:13

标签: java android objectanimator

当我第一次按下按钮时,按下其他按钮  信件,但当我再按一次时没有任何反应:
 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";
    }
}

1 个答案:

答案 0 :(得分:0)

我在this.d = -1;

中添加了void btn(String str) {}

现在它正常工作!