vxh.viet
4/15/2016 - 8:33 AM

How to know when a view is fully created ?

How to know when a view is fully created ?

Source: tutsplus, StackOverflow

Question: How to know when a view fully created?

Answer:

Since we only know after measuring the layout how much space our ImageView fills, we add an OnGlobalLayoutListener. In the onGlobalLayout method, we can intercept the event that the layout has been drawn and query the size of our view.

 yourView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //view has been drawn, do your thing here.
            }
        });