androidandroid-layoutandroid-viewtextviewandroid-viewtreeobserver

View draw complete callback


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.


Solution

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