You should just be usingmLayout.getViewTreeObserver()
inonGlobalLayout()
, rather than trying to access the_old_one. Eg.
mLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
public void onGlobalLayout() {
scrollToGridPos(getCenterPoint(), false);
mLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});