設置一個動畫播放這一觀點。如果你想立即播放的動畫,使用startAnimation這種方法提供瞭允許細粒度控制的起始時間和失效,
但你必須確保:1)動畫開始時間 2)動畫應該開始時的觀點,將被視為無效。
[java]
<span id="result_box" lang="zh-CN"></span>
/**
* Sets the next animation to play for this view.
* If you want the animation to play immediately, use
* startAnimation. This method provides allows fine-grained
* control over the start time and invalidation, but you
* must make sure that 1) the animation has a start time set, and
* 2) the view will be invalidated when the animation is supposed to
* start.
*
* @param animation The next animation, or null.
*/
public void setAnimation(Animation animation) {
mCurrentAnimation = animation;
if (animation != null) {
animation.reset();
}
}
現在開始指定的動畫。
[java]
/**
* Start the specified animation now.
*
* @param animation the animation to start now
*/
public void startAnimation(Animation animation) {
animation.setStartTime(Animation.START_ON_FIRST_FRAME);
setAnimation(animation);
invalidateParentCaches();
invalidate(true);
}
建議使用
startAnimation來啟動動畫,setAnimation啟動動畫是需要條件的
摘自 WYHuan1030