View draw complete callback

6.7k Views Asked by At

What event signifies that the draw of a View is complete?

I know about ViewTreeObserver listeners, but I couldn't find the 'final' one, which indicates, that the job is done.

3

There are 3 best solutions below

1
On BEST ANSWER

What event signifies that the draw of a TextView is complete?

There is no such hook for View class (or TextView). There is, however, onDraw() method which is called when the view should render its content.

So you can do:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // Finished drawing. Do other stuff.
    // However you must check if this is the first or subsequent call.
    // Each call to "invalidate()" will trigger re-drawing.
}
0
On

If I understand your question correctly the method you are looking for is onWindowFocusChanged(boolean hasFocus). Or else you could try the onPostResume() method.

4
On

yourView.post(someRunnable) ensures, that someRunnable will be executed after the view is laid out and drawn.