How to start Animation immediately after onCreate?

前端 未结 7 1649
借酒劲吻你
借酒劲吻你 2020-12-15 06:58

I am following http://developer.android.com/guide/topics/graphics/view-animation.html#frame-animation with minor changes. I have decided to make the animation loop and want

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 07:43

    Have a flag set in onAttachedToWindow() and then in onWindowFocusChanged() check it and start the animation.

    @Override
    void onWindowFocusChanged(boolean hasFocus) {
        if (hasFocus & mbFlag) {
            // start animation.
        }
    }
    

    Update

    Simply extend the ImageView class and override onFocusChange method. Then in your activity set the focus to it by calling animImg.requestFocus(). The animation should start when it gets focused. Make sure your imageview is focusable.

    If this does not work, you may want to override the onAttachedToWindow() method also. Set a flag in there and check before starting the animation.

    @Override
    void onFocusChange(boolean hasFocus) {
        if (hasFocus) {
            // start animation.
        }
    }
    

提交回复
热议问题