title: TextView setGravity not working (ignored) with ViewGroup programmatically
body: <p>I need to have full control of the layout of view so I use ViewGroup as follows:</p>
  
  <pre><code>        ViewGroup wrapper = new ViewGroup(getContext()) {
              @Override
              protected void onLayout(boolean changed, int l, int t, int r, int b) {
                  setClipChildren(false);
                  for (int c = 0; c &lt; this.getChildCount(); c++) {
                      View v = this.getChildAt(c);
                      ViewGroup.LayoutParams lp = v.getLayoutParams();
                      //Log.d(TAG, "layout " + c + " w:" + lp.width + " h:" + lp.height);
                      v.layout(0, 0, lp.width, lp.height);
                  }
              }
          };
  
          float nextY = dipY;
          for (SwipeMarkdown.Element e : markdown) {
              TextView tv = new TextView(getContext());
              tv.setText(e.text);
              tv.setTextSize(e.fontSize);
              tv.setTextColor(e.textColor);
              tv.setGravity(Gravity.CENTER);// e.textAlignment);
              tv.setBackgroundColor(Color.YELLOW);
              tv.setX(0);
              tv.setY(nextY);
              tv.measure((int)dipW, (int)dipH);
              int mh = tv.getMeasuredHeight();
              nextY = nextY + mh + e.lineSpacing;
              wrapper.addView(tv, new ViewGroup.LayoutParams((int)dipW, (int) mh));
          }
  
          wrapper.setY((dipH - nextY)/2); // center vertically in self
          viewGroup.addView(wrapper, new ViewGroup.LayoutParams((int) dipW, ViewGroup.LayoutParams.WRAP_CONTENT));
      }
  </code></pre>
  
  <p>Everything works fine except I cannot get setGravity() to align the text.</p>
  
  <p>What am I missing?</p>
  
  <p>Thx</p>
  
  <p>UPDATE:  @pskink gave me the answer!  Call to <code>measure()</code> requires the use of a <code>MeasureSpec</code> as follows:</p>
  
  <pre><code>    tv.measure(View.MeasureSpec.makeMeasureSpec(dipW, View.MeasureSpec.EXACTLY),
                 View.MeasureSpec.makeMeasureSpec(dipH, View.MeasureSpec.AT_MOST));
  </code></pre>