문제

I'd like to start an animation right after an activity is created. The problem is that I have to call the method once everything is showed on the screen, let's say one second after being showed for the first time.

In other words, I'm looking for a method to be executed right after onCreate() but after the activity is shown:

Activity lifecicle

Thanks!

도움이 되었습니까?

해결책

You can't assume that the GUI has been drawn in onCreate(). In fact it often is not.

The best way to catch when everything has finally be rendered on screen is with:

 @Override
 public void onWindowFocusChanged (boolean hasFocus) { ... }

Put your thing in a timer here.

다른 팁

Assuming you set up your layout in onCreate() it looks like you can use setStartTime(long millis) on your animation object.

public void onCreate(...)
{
    super.onCreate(...);
    setContentView(R.layout.your_layout);
    //  do whatever else you need to
    // create your animation
    animation.setStartTime(1000); // should start it in one second
}

You can start your animation in onPostResume(), which is invoked after onResume() finished.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top