title: View.getHeight() returns 0 when using getViewTreeObserver()
body: <p>I'm trying to get a textView height before draw it, so i use getViewTreeObserver code from other questions:</p>
  
  <pre><code>private TextView mTextView;
  private int mTextViewHeight = 0;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) { 
  mRootView = inflater.inflate(R.layout.fragment, container, false);
  
  mTextView = (TextView) mRootView.findViewById(R.id.text);
  
  mTextView.getViewTreeObserver().addOnGlobalLayoutListener(
                  new ViewTreeObserver.OnGlobalLayoutListener() {
                      @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                      @Override
                      public void onGlobalLayout() {
                          mTextViewHeight = mTextView.getHeight(); // Tried with getMeasured() too
  
                          if (Utils.hasJellyBean()) {
                              mTextView.getViewTreeObserver()
                                      .removeOnGlobalLayoutListener(this);
                          } else {
                              mTextView.getViewTreeObserver()
                                      .removeGlobalOnLayoutListener(this);
                          }
                      }
                  });
  </code></pre>
  
  <p>Using this code, i always get mTextViewHeight = 0. I've tried debuggin, and looking at entry point of OnGlobalLayoutListener, thread never access to "mTextViewHeight = mTextView.getHeight();" line.</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The answer was great, but my error is that when i want to use mTextViewHeight in code, this code was been executed before entry on the Listener, so the value i was getting was the inital value. To fix that, i have to put inside the listener the code i want to use with the textView height. </p>
  
  <p>BEFORE FIXED:</p>
  
  <pre><code>private TextView mTextView;
      private int mTextViewHeight = 0;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                   Bundle savedInstanceState) { 
      mRootView = inflater.inflate(R.layout.fragment, container, false);
  
      mTextView = (TextView) mRootView.findViewById(R.id.text);
  
      mTextView.getViewTreeObserver().addOnGlobalLayoutListener(
                      new ViewTreeObserver.OnGlobalLayoutListener() {
                          @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                          @Override
                          public void onGlobalLayout() {
                              mTextViewHeight = mTextView.getHeight(); // Tried with getMeasured() too
  
                              if (Utils.hasJellyBean()) {
                                  mTextView.getViewTreeObserver()
                                          .removeOnGlobalLayoutListener(this);
                              } else {
                                  mTextView.getViewTreeObserver()
                                          .removeGlobalOnLayoutListener(this);
                              }
                          }
                      });
  
      if(mTextViewHeight &gt; maxHeightAllowed) {
          mTextViewHeight /= 2;
      } else {
          String text = new String("");
          for(int i = 0; i &lt; mTextViewHeight.lenght(); i++)
          text = text + getNextWord[i];
      }
  }
  </code></pre>
  
  <p>AFTER FIXING</p>
  
  <pre><code>private TextView mTextView;
  private int mTextViewHeight = 0;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) { 
  mRootView = inflater.inflate(R.layout.fragment, container, false);
  
  mTextView = (TextView) mRootView.findViewById(R.id.text);
  
  mTextView.getViewTreeObserver().addOnGlobalLayoutListener(
                  new ViewTreeObserver.OnGlobalLayoutListener() {
                      @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                      @Override
                      public void onGlobalLayout() {
                          mTextViewHeight = mTextView.getHeight(); // Tried with getMeasured() too
                          if(mTextViewHeight &gt; maxHeightAllowed) {
                              mTextViewHeight /= 2;
                          } else {
                              String text = new String("");
                              for(int i = 0; i &lt; mTextViewHeight.lenght(); i++)
                              text = text + getNextWord[i];
                          }
  
                          if (Utils.hasJellyBean()) {
                              mTextView.getViewTreeObserver()
                                      .removeOnGlobalLayoutListener(this);
                          } else {
                              mTextView.getViewTreeObserver()
                                      .removeGlobalOnLayoutListener(this);
                          }
                      }
                  });
  </code></pre>
  
  <p>}</p>