运用连续动画ImageView的Andr​​oid中 [英] Applying successive animations to ImageView in Android

查看:120
本文介绍了运用连续动画ImageView的Andr​​oid中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请连续动画(说ScaleAnimation),以呈现出资源图像的ImageView的。动画是由一个按钮触发。例如,我想在每次点击按钮逐次放大图像。

我的动画设置fillAfter =真。然而,所有的动画从ImageView的的原始状态开始。看来,如果在ImageView的重置其状态和动画始终是相同的,而不是从previous动画的最终状态开始。

我在做什么错了?

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);    Button按钮=(按钮)findViewById(R.id.Button01);
    button.setOnClickListener(新OnClickListener(){        公共无效的onClick(查看为arg0){
            动画();        }});
}私人无效动画(){
    ImageView的ImageView的=(ImageView的)findViewById(R.id.ImageView01);    ScaleAnimation规模=新ScaleAnimation((浮点)1.0,(浮点)1.5,(浮点)1.0,(浮点)1.5);
    scale.setFillAfter(真);
    scale.setDuration(500);
    imageView.startAnimation(规模);
}


解决方案

  

看起来好像在ImageView的复位
  它的状态和动画总是
  相同的,而不是从起始
  在previous动画的最终状态。


precisely!我敢肯定有一个使用 fillAfter =真正的,但我还没有想出它的地步呢。

你需要做的是建立一个 AnimationListener 每个动画相关性,并做了一些听者的 onAnimationEnd()真正坚持动画的最终状态。我还没有与 ScaleAnimation 发挥,所以我不是很确定为坚持到底状态的方式是什么。如果这是一个 AlphaAnimation ,从 1.0 来将 0.0 ,你会作出小部件看不见 GONE onAnimationEnd(),例如

I would like to apply successive animations (say ScaleAnimation) to an ImageView showing a resource image. The animation is triggered by a button. For example, I would like to incrementally enlarge an image upon each button click.

I've set fillAfter="true" on the animation. However, all the animations start from the original state of the ImageView. It seems as if the ImageView resets its state and the animation is always the same, instead of starting from the final state of the previous animation.

What am I doing wrong?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button button = (Button)findViewById(R.id.Button01);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {
            animate();

        }});
}

private void animate() {
    ImageView imageView = (ImageView) findViewById(R.id.ImageView01);

    ScaleAnimation scale = new ScaleAnimation((float)1.0, (float)1.5, (float)1.0, (float)1.5);
    scale.setFillAfter(true);
    scale.setDuration(500);
    imageView.startAnimation(scale); 
}

解决方案

It seems as if the ImageView resets its state and the animation is always the same, instead of starting from the final state of the previous animation.

Precisely! I'm sure there's a use for fillAfter="true", but I haven't figured out the point for it yet.

What you need to do is set up an AnimationListener on each Animation of relevance, and do something in the listener's onAnimationEnd() to actually persist the end state of your animation. I haven't played with ScaleAnimation so I'm not quite sure what the way to "persist the end state" would be. If this were an AlphaAnimation, going from 1.0 to 0.0, you would make the widget INVISIBLE or GONE in onAnimationEnd(), for example.

这篇关于运用连续动画ImageView的Andr​​oid中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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