Remove listener from ViewTreeObserver

后端 未结 1 1426
萌比男神i
萌比男神i 2020-12-09 16:55

I need to listen for exact one global layouting event to initially set correct scrolling positions. After searching a little why my calls to scrollTo(x,y) seem

相关标签:
1条回答
  • 2020-12-09 17:13

    You should just be using mLayout.getViewTreeObserver() in onGlobalLayout(), rather than trying to access the old one. Eg.

    mLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        public void onGlobalLayout() {
            scrollToGridPos(getCenterPoint(), false);
            mLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);        
        }
    });
    
    0 讨论(0)
提交回复
热议问题