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
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.
}
}
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.
}
}