title: How to programmatically align an Android TextView to the right of another TextView
body: <p>In the below code I have created two text views and added them programmatically to a relative layout.  I want to align them side by side.</p>
  
  <p>The code runs fine but is not placing the new <code>TextView</code> to the right of previous <code>TextView</code> instead the new <code>TextView</code> is positioned at margin (0,0,0,0) i.e. upper right corner of the screen:</p>
  
  <pre><code>    super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      relativeLayout= (RelativeLayout) findViewById(R.id.relative_Layout);
  
      textView[0] = new TextView(this);//creates first textview
      textView[0].setId(0);
      textView[0].setText("1");
      textView[0].setBackgroundResource(R.drawable.shape);//parses an image from shape.xml
  
      relativeLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
      textView[0].setLayoutParams(relativeLayoutParams);
  
      relativeLayout.addView(textView[0]);//creates another textview
  
      textView[1] = new TextView(this);
  
      textView[1].setBackgroundResource(R.drawable.shape);
  
      RelativeLayout.LayoutParams relativeLayoutParams=
              new RelativeLayout.LayoutParams((RelativeLayout.LayoutParams.WRAP_CONTENT),(RelativeLayout.LayoutParams.WRAP_CONTENT));//create params for new textview
  
      relativeLayoutParams.addRule(RelativeLayout.RIGHT_OF, textView[0].getId());//to align the textview side by side
      textView[1].setText("2");
  
      relativeLayout.addView(textView[1], relativeLayoutParams);
  </code></pre>