Ras*_*mus 2 android android-animation
嗨,我想动画一个视图的高度在android说每5秒: -
我使用下面的代码: -
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;
}
}
Run Code Online (Sandbox Code Playgroud)
并像这样初始化它: -
Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
delta.startAnimation(anidelta);
Run Code Online (Sandbox Code Playgroud)
但有了这个我得到以下: -
我希望高度从之前的高度开始动画,而不是每次从0开始.有人可以帮我这里
编辑1: - 我这样做了
Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
anidelta.setFillAfter(true);
delta.startAnimation(anidelta);
Run Code Online (Sandbox Code Playgroud)
但它仍然从0到新高度动画.
好的,这就是我最终解决它的方法: -
public class ResizeAnimation extends Animation
{
View view;
int startH;
int endH;
int diff;
public ResizeAnimation(View v, int newh)
{
view = v;
startH = v.getLayoutParams().height;
endH = newh;
diff = endH - startH;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
view.getLayoutParams().height = startH + (int)(diff*interpolatedTime);
view.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;
}}
Run Code Online (Sandbox Code Playgroud)