一个动画的android观的高度, [英] Animating the height of a view android

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

问题描述

你好我试图动画的android中视图的高度说,每5秒: -

Hi I am trying to animate the height of a view in android say every 5 seconds :-


  1. 的高度从0到5

  2. 的高度去-5至10

  3. 的高度去10至3等

我使用的是code如下: -

I am using the code below :-

    public class ShowAnimation extends Animation{
    float finalHeight;
    View imageview;

    public ShowAnimation(View view,float deltaheight){
        this.imageview=view;
        this.finalHeight=deltaheight;
    }

    protected void applyTransformation(float interpolatedtime,Transformation t){
        imageview.getLayoutParams().height=(int)(finalHeight*interpolatedtime);
        imageview.requestLayout();
    }
    @Override
    public void initialize(int width, int height, int parentWidth,
            int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

    @Override
    public boolean willChangeBounds() {
        return true;
    }
    }

和初始化它是这样的: -

and initialize it like this:-

Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
delta.startAnimation(anidelta);

但有了这个,我得到如下: -

But with this i get the below:-


  1. 的高度从0到5

  2. 的高度从0到10

  3. 的高度从0到3

我想的高度从其previous高度,而不是从0每次动画。
是否有人可以帮助我在这里

i want the height to be animated from its previous height rather than from 0 everytime. Can someone please help me here

EDIT1 -
我这样做

- I did this

Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
anidelta.setFillAfter(true);
delta.startAnimation(anidelta);

但它仍然从0到动画的newheight。

But it still animates from 0 to the newheight.

推荐答案

尝试动画集。我不知道这是否是你想要的。

Try animation set. I am not sure whether this is what you want.

有关动画1:高度从0到5

动画2为:高度从0到10

为动画3:高度从0到3

Animation 1 for : height goes from 0 to 5
Animation 2 for : height goes from 0 to 10
Animation 3 for : height goes from 0 to 3

public void applyAnimation(ImageView ivDH) {
    System.out.println("Inside applyAnimation()");
    scaleAnim1 = new ScaleAnimation(0, 5, 0, 5);
    scaleAnim1.setDuration(5000);
    scaleAnim1.setRepeatCount(0);
    scaleAnim1.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleAnim1.setFillAfter(true);

    scaleAnim2 = new ScaleAnimation(-5, 10, -5, 10);
    scaleAnim2.setDuration(5000);
    scaleAnim2.setRepeatCount(0);
    scaleAnim2.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleAnim2.setFillAfter(true);

    scaleAnim3 = new ScaleAnimation(10, 3, 10, 3);
    scaleAnim3.setDuration(5000);
    scaleAnim3.setRepeatCount(0);
    scaleAnim3.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleAnim3.setFillAfter(true);

    AnimationSet animationSet = new AnimationSet(true);
    animationSet.addAnimation(scaleAnim1);
    animationSet.addAnimation(scaleAnim2);
    animationSet.addAnimation(scaleAnim3);
    animationSet.setDuration(15000);
    animationSet.setFillAfter(true);

    ivDH.clearAnimation();
    ivDH.startAnimation(animationSet);
}

这篇关于一个动画的android观的高度,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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