title: Authorative way to override onMeasure()?
body: <p>What's the correct way of overriding onMeasure()? I've seen various approaches. For example, <em>Professional Android Development</em> uses MeasureSpec to calculate the dimensions, then ends with a call to setMeasuredDimension(). For example:</p>
  
  <pre><code>@Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
  int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
  int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
  this.setMeasuredDimension(parentWidth/2, parentHeight);
  }
  </code></pre>
  
  <p>On the other hand, as per <a href="https://stackoverflow.com/questions/2159320/how-to-size-an-android-view-based-on-its-parents-dimensions">this post</a>, the "correct" way is to use MeasureSpec, call setMeasuredDimensions(), <strong>followed by</strong> a call to setLayoutParams(), and ending with a call to super.onMeasure(). For example:</p>
  
  <pre><code>@Override 
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
  int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
  int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
  this.setMeasuredDimension(parentWidth/2, parentHeight);
  this.setLayoutParams(new *ParentLayoutType*.LayoutParams(parentWidth/2,parentHeight));
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }
  </code></pre>
  
  <p>So which is the right way? Neither approach has worked 100% for me. </p>
  
  <p>I guess really what I'm asking is does anyone know of a tutorial that explains onMeasure(), layout, dimensions of child views etc.? </p>