Skip to content

Instantly share code, notes, and snippets.

@vxhviet
Last active April 15, 2016 09:07
Show Gist options
  • Select an option

  • Save vxhviet/b8b44a50fd1f17ea231c480c666d5697 to your computer and use it in GitHub Desktop.

Select an option

Save vxhviet/b8b44a50fd1f17ea231c480c666d5697 to your computer and use it in GitHub Desktop.
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.
            }
        });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment