title: Center in parent is not working for custom relative layout
body: <p>I'm trying to create custom layout "SquareBox" based on relative layout to hold a ImageView in center.
  And this custom layout will always be in square size (depend on ImageView's height and width).</p>
  
  <pre><code>protected void onMeasure(int width, int height) {
      super.onMeasure(width, height);
      int measuredWidth = getMeasuredWidth();
      int measuredHeight = getMeasuredHeight();
      int size;
      if (measuredWidth &gt; measuredHeight) {
          size = measuredWidth;
      } else {
          size = measuredHeight;
      }
      setMeasuredDimension(size, size);
  }
  </code></pre>
  
  <p>Here is my layout code:</p>
  
  <pre><code>  &lt;com.example.tools.SquareBox
          android:id="@+id/square_box"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:gravity="center"
          android:background="@android:color/darker_gray"&gt;
  
      &lt;ImageView
          android:id="@+id/canvas_image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_margin="0dp"
          android:layout_centerInParent="true"
          android:adjustViewBounds="true"
          android:scaleType="fitCenter"
          tools:src="@drawable/demo_image" /&gt;
  &lt;/com.example.tools.SquareBox&gt;
  </code></pre>
  
  <p>It is working fine but the image-view is not in center of this custom view.
  I've tried following:
  ->android:layout_centerInParent="true" for ImageView.</p>
  
  <p>->android:gravity="center" for "SquareBox".</p>
  
  <p>->Adding CENTER_IN_PARENT programmatically to ImageView in SquareBox's onMeasure method.<br/></p>
  
  <p>But nothing is working.
  What am i missing here?</p>