如何编程动画的ImageView的 [英] How to programatically animate an ImageView

查看:124
本文介绍了如何编程动画的ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图点击该图像视图时,动画的ImageView的。

I am trying to animate an ImageView when the said image view is clicked.

具体来说,我想的ImageView的尺寸变大(比如0.20大)和立即收缩回原来的大小)。

Specifically i want the size of the ImageView gets bigger (say .20 bigger) and the immediately shrink back to its original size).

到目前为止,我一直在尝试这个code,没有运气。

So far i have been experimenting with this code with no luck.

// thumbLike is the imageView i would like to animate.
button.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.5f, 1.0f, 2.5f,
                                    Animation.RELATIVE_TO_SELF, 0.5f,
                                    Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnim.setInterpolator(new LinearInterpolator());
        scaleAnim.setDuration(1500);
        thumbLike.startAnimation(scaleAnim);
        thumbLike.setAnimation(null);
    }
});

任何人都可以建议我用一个可能的解决方案?

Can anyone suggest me with a possible solution?

编辑#1

这是通过XML工作由Hardik4560的回答:

It is working through XML as answered by Hardik4560:

// finally i use this code to execute the animation
Animation animationScaleUp = AnimationUtils.loadAnimation(this, R.anim.scale_up);
Animation animationScaleDown = AnimationUtils.loadAnimation(this, R.anim.scale_down);

AnimationSet growShrink = new AnimationSet(true);
growShrink.addAnimation(animationScaleUp);
growShrink.addAnimation(animationScaleDown);
thumbLike.startAnimation(growShrink);

和XML

SCALE_UP
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <scale
        android:fromXScale="1.0"
        android:toXScale="1.5"
        android:fromYScale="1.0"
        android:toYScale="1.5"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000" />
</set>

SCALE_DOWN
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <scale
        android:fromXScale="1.5"
        android:toXScale="1.0"
        android:fromYScale="1.5"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="1000" />
</set>

PS:这是尴尬的,因为我已经接受了答案。我想它的动画看起来不太平滑的方式@tharkbad但现在之间@ Hardik4560的回答结合起来。

ps: this is awkward, since i already accepted an answer. I am trying to combine between @tharkbad and @Hardik4560 's answers yet now the way it animates does not look smooth.

在scale_up动画过程中,它有点像被跳过,以动画的结尾,然后立即开始scale_down动画。我想我有一点玩弄它。

during the scale_up animation, it kinda look like being "skip" to the end of animation and then immediately starting scale_down animation. I guess i have to play around with it a bit.

推荐答案

我用这个来实现人口信息网的弹出效果,

I use this to achieve popin popout effect,

看看是否有使用你的公司

See if its of any use to you

弹出。

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator"    >
    <scale
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="0.5"
        android:fromYScale="0.5"
        android:toXScale="1.0"
        android:toYScale="1.0"
        android:duration="500" />

</set>

流行在

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator"    >
    <scale
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="0.0"
        android:toYScale="0.0"
        android:duration="500" />

</set>

这篇关于如何编程动画的ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆