daily pastebin goal
95%
SHARE
TWEET

Untitled

a guest Feb 24th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final ViewGroup myViewGroup = (ViewGroup)findViewById(R.id.my_viewgroup);
  2. ViewTreeObserver vto = myViewGroup.getViewTreeObserver();
  3. vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
  4.     @Override
  5.     public void onGlobalLayout() {
  6.         //myViewGroup should now have dimensions, but sometimes
  7.         //it takes two passes, so...
  8.         if(myViewGroup.getWidth() == 0) return;
  9.  
  10.         //Set whatever stuff here
  11.         myTileSizes = whateverSize;
  12.  
  13.         //Remove this listener -- no longer needed
  14.         myViewGroup.getViewTreeObserver().removeGlobalOnLayoutListener(this);
  15.     }
  16. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top