你好我試圖動畫android的視圖的高度的高度說,每5秒: -動畫的android視圖
- 高度從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
我希望高度能夠從它以前的高度動畫而不是從0開始。 可有人請點擊這裏
EDIT1幫助我: - 我這樣做
Animation anidelta = new ShowAnimation(delta, deltaheight);
anidelta.setDuration(500/* animation time */);
anidelta.setFillAfter(true);
delta.startAnimation(anidelta);
但它仍然從0到動畫的newheight。
set animation.setFillAfter(true);它應該解決問題。 –
@ShreyaShah我做到了,但不起作用。請參閱我的編輯 – Rasmus