title: How to correctly override onLayout Method in a Viewgroup class
body: <p>I have a class extending from a view group class. Now I know that in onLayout you have to call the layout method on each children. The question here is what values should be passed to the child layout.</p>
  
  <p>In my view I inflate a xml and attach it to this class (The width and height are defined in xml). In onlayout I get one child count which is correct but the width and height of the child is returning 0. How I can get the width and height of the child.</p>
  
  <p>And if I am setting the position and measurement in then what is the onmeasure method is for? I thought we were suppose to measure the child in there.</p>
  
  <p>Below is some source code for reference.</p>
  
  <pre><code>public BaseWidget(Context context, int resourceId) {
      super(context);
      initWithResourceID(resourceId);
  }
  
  private void initWithResourceID(int resourceId) {
      inflate(getContext(), resourceId, this);
  }
  
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
      final int count = getChildCount();
      for (int i = 0; i &lt; count; i++) {
          View child = getChildAt(i);
          getChildAt(i).layout(l, t, r, b);
  //      getChildAt(i).layout((int)child.getX(), (int)(child.getY() + child.getMeasuredHeight()), (int) (child.getX() + child.getMeasuredWidth()), (int)child.getY());
      }
  }
  </code></pre>
  
  <p>The xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="150dp"
  android:layout_height="90dp"
  android:background="@color/ripple_material_light"
  android:orientation="vertical"
  android:padding="20dp"&gt;
  
  &lt;RelativeLayout
      android:id="@+id/texts"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;TextView
          android:id="@+id/title"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:text="1" /&gt;
  
      &lt;TextView
          android:id="@+id/asideTitle"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:text="2" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;View
      android:id="@+id/detailedView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
  &lt;/View&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When I call <code>getChildAt(i).layout(l, t, r, b);</code> the child is drawn on the whole parent.</p>
  
  <p>When I call</p>
  
  <pre><code>getChildAt(i).layout((int)child.getX(), (int)(child.getY() + 
  child.getMeasuredHeight()), (int) (child.getX() + 
  child.getMeasuredWidth()), (int)child.getY());
  </code></pre>
  
  <p>nothing is drawn</p>
  
  <p>So basically I want to know what should we pass to the child.. and what is the major difference between onmeasure and onlayout. I hope I make my question clear. </p>