0

When the user launches an app, (I guess) the interface is shown by components, like Button, TextView, LinearLayout and so on.

The question is how to detect such a component has just been drawn (i.e. user can see it)?

For example, right after it is drawn, output a string "component_id is drawn".

JackWM
  • 10,085
  • 22
  • 65
  • 92

1 Answers1

3

Use a ViewTreeObserver.

view.getViewTreeObserver().addOnDrawListener(new OnDrawListener() {

        @Override
        public void onDraw() {

                   Log.i("component","is drawn");

        }

    });
ElDuderino
  • 3,253
  • 2
  • 21
  • 38
  • If it matters in the case, onDraw() is invoked when a view is about to be drawn, see [here](http://developer.android.com/reference/android/view/ViewTreeObserver.OnDrawListener.html#onDraw()) – Onik Mar 23 '14 at 15:32