你好,我正在尝试在Android中每5秒动画一个视图的高度:
- 高度从0到5
- 高度从5到10
- 高度从10到3等等
我正在使用以下代码:
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;
}
}
并且要像这样初始化:
Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
delta.startAnimation(anidelta);
但是我得到以下结果:
- 高度从0变为5
- 高度从0变为10
- 高度从0变为3
编辑1: 我已经做到了。
Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
anidelta.setFillAfter(true);
delta.startAnimation(anidelta);
但它仍会从0动画到新高度。