Fragment - removeGlobalOnLayoutListener IllegalStateException

前端 未结 3 1938
一向
一向 2020-12-09 03:35

I\'m trying to get the height and width of an ImageView in a Fragment with the following ViewTreeObserver:

import andr         


        
3条回答
  •  鱼传尺愫
    2020-12-09 04:22

    try this :

       ViewTreeObserver observer = imageViewPicture.getViewTreeObserver();
       observer.addOnGlobalLayoutListener (new OnGlobalLayoutListener () {
        @Override
         public void onGlobalLayout() {
    
           imageViewPicture.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });
    

提交回复
热议问题