title: Custom View not visible
body: <p>I am trying to add the imageViews to a Custom RelativeLayout programmtically. The problem is for some reason the childViews of the custom RelativeLayout aren't visible. What am I doing wrong?</p>
  
  <pre><code>public class MyViewGroup extends RelativeLayout{
  
      Context mContext;
  
      public MyViewGroup(Context context) {
          super(context);
  
          mContext = context;
  
          init();
      }
  
      public MyViewGroup(Context context, AttributeSet attrs) {
          super(context, attrs);
  
          mContext = context;
          init();
      }
  
      public MyViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
  
          mContext = context;
          init();
      }
  
      @Override
      protected void onLayout(boolean changed, int l, int t, int r, int b) {
  
      }
  
      void init()
      {
          for(int i=0; i&lt;2; i++)
          {
              ImageView myImage = new ImageView(mContext);
  
              if(i==0)
                  myImage.setBackgroundColor(Color.CYAN);
              else
                  myImage.setBackgroundColor(Color.MAGENTA);
  
  
              myImage.setId(i);
  
              RelativeLayout.LayoutParams params= new LayoutParams(50+i*70, 50+i*70);
              myImage.setLayoutParams(params);
  
  
              ImageView sImage = new ImageView(mContext);
  
              if(i==0)
              sImage.setBackgroundColor(Color.RED);
              else
                  sImage.setBackgroundColor(Color.GREEN);
  
  
              RelativeLayout.LayoutParams p= new LayoutParams(200+i*70, 200+i*70);
              p.addRule(RelativeLayout.ALIGN_TOP | RelativeLayout.ALIGN_LEFT, myImage.getId());
              sImage.setLayoutParams(p);
  
              addView(myImage);
              addView(sImage);
  
          }
  
      }
  }
  </code></pre>
  
  <p>inside layout file.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;
  
      &lt;TextView android:text="@string/hello_world" android:layout_width="wrap_content"
          android:layout_height="wrap_content" /&gt;
  
      &lt;user.com.MyViewGroup
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>What am I missing?</p>
  
  <p>Best Regards</p>
  
  <p>EDIT:</p>
  
  <pre><code>        RelativeLayout.LayoutParams params= new LayoutParams(200+i*70, 200+i*70);
          params.addRule(RelativeLayout.CENTER_IN_PARENT);
          myImage.setLayoutParams(params);
  
  
          ImageView sImage = new ImageView(mContext);
  
          sImage.setBackgroundColor(Color.RED);
  
  
          RelativeLayout.LayoutParams p= new LayoutParams(20+i*70, 20+i*70);
          p.addRule(RelativeLayout.CENTER_IN_PARENT);
          p.addRule(RelativeLayout.ALIGN_BOTTOM, myImage.getId());
          sImage.setLayoutParams(p);
  
          addView(myImage);
          addView(sImage);
  </code></pre>