onClick动画无法正常工作? (图书馆)

时间:2015-03-22 22:25:14

标签: android animation

今天是我的第一次尝试,在我的Android项目中实现了一个库,我选择了这个Android View Animation库,它非常好,并且它适用于onCreate,但是如果我想将它实现到我的按钮,动画实际上没有播放。有什么问题?

这是我的代码:

 public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                YoYo.with(Techniques.ZoomIn)
                        .duration(700)
                        .playOn(findViewById(R.id.button));
                input.setText(null);
                Intent intent = new Intent(this, Szabaly.class);
                startActivity(intent);
                break;

1 个答案:

答案 0 :(得分:1)

我认为你没有意识到“playOn”方法是异步的。这意味着下一行代码将在此方法之后立即实现,而无需等待动画完成。

请继续使用此代码:

YoYo.with(Techniques.ZoomIn).duration(700).withListener(new Animator.AnimatorListener() {

    @Override
    public void onAnimationStart(Animator animation) {}

    @Override
    public void onAnimationEnd(Animator animation) {

        input.setText(null);
        Intent intent = new Intent(this, Szabaly.class);
        startActivity(intent);
    }

    @Override
    public void onAnimationCancel(Animator animation) {}

    @Override
    public void onAnimationRepeat(Animator animation) {}
}).playOn(findViewById(R.id.button));