title: how to set android:layout_centerInParent="true" attribute in custom view
body: <p>i am continuously searching and trying to sort out a issue in custom view and Relative layout.
  i found multiple solution but only few of solution are usefull,but they not fulfilling my requirement completely.
  <a href="https://stackoverflow.com/questions/2159320/how-to-size-an-android-view-based-on-its-parents-dimensions"></p>
  <p>partial solution 1</a>.</p>
  <p><a href="https://stackoverflow.com/questions/4074937/android-how-to-get-a-custom-views-height-and-width"> partial solution 2</a>.</p>
  <p>via these solution i can manage the height and width of my custom view, but i just want to align my custom view in center of parent RelativeLayout,
  code which i am trying throw hit-and-run is below. ;)
  <b> JAVA CODE</b></p>
  <pre><code>public class MyActiveView extends View {
  public Movie mMovie;
  public long movieStart;
  private int gifId;
  
  
  
  public MyActiveView(Context context, AttributeSet attrs) {
      super(context, attrs);
      initializeView();
  }
  
  
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
      int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
      this.setMeasuredDimension(parentWidth / 2, parentHeight);
  }
  
  
  private void initializeView() {
      InputStream is = getContext().getResources().openRawResource(R.raw.pj_logo1);
      mMovie = Movie.decodeStream(is);
  }
  
  @Override
  protected void onDraw(Canvas canvas) {
      canvas.drawColor(Color.TRANSPARENT);
      super.onDraw(canvas);
      long now = android.os.SystemClock.uptimeMillis();
      if (movieStart == 0) {
          movieStart = now;
      }
      if (mMovie != null) {
          int relTime = (int) ((now - movieStart) % mMovie.duration());
          mMovie.setTime(relTime);
          mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight() - mMovie.height());
          this.invalidate();
      }
  }
  
  public int getActiveResource() {
      return this.gifId;
  }
  
  public void setActiveResource(int resId) {
      this.gifId = resId;
      initializeView();
  }
  }
  </code></pre>
  <p><b> XML CODE </b></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;&gt;
  
  &lt;ImageView
      android:id=&quot;@+id/backsourceImagesplash&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:scaleType=&quot;fitXY&quot;
      android:src=&quot;@drawable/bg_blur&quot; /&gt;
  
  &lt;ImageView
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:src=&quot;@color/colorTransparentWhite&quot; /&gt;
  
  
  &lt;RelativeLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;256dp&quot;
      android:layout_centerVertical=&quot;true&quot;
      android:gravity=&quot;centre&quot;&gt;
  
      &lt;pj.com.pjlib.activity_base.support_class.MyActiveView
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot; /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>i want to set my custom active view layout in centre of its parent Relative Layout, but stuked in it. any help will be appreciated.</p>
  <p><a href="https://i.stack.imgur.com/CayIs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CayIs.png" alt="i want result like this." /></a>
  <a href="https://i.stack.imgur.com/uLa8y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uLa8y.png" alt="but result of my code is " /></a></p>
  <p>check the alignment of both image,i am trying for attribute android:layout_centerInParent=&quot;true&quot;, according to Relative layout support the &quot;congrats image&quot; should be in center, but it's not happening.</p>
  <p>so i am thinking,i missed something in my custom view class but what is that, i don't know.</p>