0

我想为按钮设置动画(即;旋转、平移)然后更改按钮的文本。不幸的是,它总是先更改按钮的文本,然后再做动画。

我怎样才能实现我的目标?

请帮助我

我的代码是这样的;

AnimationSet set = new AnimationSet(true);

                    Animation anim1 = new RotateAnimation(0, 360, 500, 750);
                    anim1.setDuration(3000);
                    anim1.setFillAfter(true);
                    set.addAnimation(anim1);

                    Animation anim2 = new RotateAnimation(0, 360, 1024, 824);
                    anim2.setDuration(3000);
                    anim2.setFillAfter(true);
                    set.addAnimation(anim2);

                    anim2.setStartOffset(3000);

                    first.clearAnimation();
                    set.setFillAfter(true);
                    first.startAnimation(set);      

                    numbers[0]=min + (int)(Math.random() * ((max - min) + 1));
4

2 回答 2

0

A better solution is to add an AnimationListener to the animation, or if you are on JB use the view property animators and the withEndAction() method. You should avoid the old animation framework if possible. It doesn't actually change the properties, it just draw the view with a transformation.

set.setAnimationListener(new AnimationListener() {
    public void onAnimationEnd() {
        // ...
    }

    public void onAnimationStart() {
    }

    public void onAnimationRepeat() {
    }
}

But I recommend the view property animations if you can use them. They are much better to work with.

于 2012-09-18T08:29:22.347 回答
0

您的代码启动动画但没有阻塞:一旦启动动画,程序就会继续。

您可以尝试获取处理程序并在正确的时间发布更改文本事件:

Handler mHandler=new Handler();
Runnable lRunnable =new Runnable()
{
    public void run() 
    {
    //Your change text code                       
    }
};
mHandler.postDelayed(lRunnable , 3000); // Or any other duration so you have the right effect
于 2012-09-17T13:18:58.003 回答