视图中的动画列表

时间:2013-06-13 00:14:32

标签: java android android-animation

我想在点击时在ImageButton中进行以下操作:

1-倍它的大小

2-在步骤1之后,开始减少直到它是一个点,同时使用淡出效果

3-保持隐身

我该怎么做?

2 个答案:

答案 0 :(得分:1)

为此使用 ScaleAnimation ,它会使ImageButton的大小加倍

ScaleAnimation  setSizeForTop = new ScaleAnimation(1, 2, 1, 2);

现在,

top.startAnimation(setSizeForTop);

缩小尺寸

setSizeForTop = new ScaleAnimation(1, .5f, 1, .5f); 

用于淡出效果我们使用

Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);

AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
this.setAnimation(animation);

表示不可见

 ImageButton.setImageVisibility(gone);

答案 1 :(得分:0)

看看在蜂窝中​​引入的ValueAnimator(但也在一个名为NineOldAndroids的库中向后移植)。

在按钮onClick中,您将从XML加载动画,或以编程方式创建动画,然后启动它。

您可以使用动画设置来一个接一个地运行多个动画。

下面是一些(未经测试的)示例代码:

    //set up the scale and fade animation set
    AnimatorSet scaleAndFadeSet = new AnimatorSet();
    scaleAndFadeSet.playTogether( ValueAnimator.ofFloat(myButton, "alpha", 1.0f, 0f), ObjectAnimator.ofFloat(myButton, "scale", 2.0f, 0f));

    // the top level animation set
    AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(myButton, "scale", 0, 2.0f),scaleAndFadeSet);
    set.setDuration(1000);// 1s animation
    set.start();