title: TextView gravity
body: <p>Has anyone tried to write his own implementation of <em>ViewGroup</em> with some TextViews in it?</p>
  
  <p>I have a problem, that TextViews in such an implementation don't respect the gravity property <code>TextView.setGravity(Gravity.CENTER)</code> and text is positioned in the top left corner.</p>
  
  <p>Can anyone help me find out why?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Ok. nevermind, I figured it out on my own already.</p>
  
  <p>If enyone is interested, I just overwrote method <code>onMeasure()</code> (for all my TextViews) and changed call from <code>super.onMeasure()</code> to <code>setMeasuredDimension(int, int)</code> and gravity started to work normally.</p>
  
  <p>Basically, in my custom layout I use the following class to display text:</p>
  
  <pre><code>private static class GravityTextView extends TextView {  
  
      public GravityTextView(Context context) {  
          super(context);  
      }
  
      @Override  
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
          setMeasuredDimension(widthMeasureSpec, heightMeasureSpec);  
      }
  
  }
  </code></pre>