1.setAnimation和startAnimation區別

設置一個動畫播放這一觀點。若是你想當即播放的動畫,使用startAnimation這種方法提供了容許細粒度控制的起始時間和失效,java

但你必須確保:1)動畫開始時間 2)動畫應該開始的觀點將被視爲無效ide


    /**
     * 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();
        }
    }

如今開始指定的動畫
動畫

/**
     * 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啓動動畫是須要條件的this

相關文章
相關標籤/搜索