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.
}
});