Align dynamically created textview and edit text in android
<p>I have a relative layout and 'n' number of textviews and edittext . I want the alignment as</p>

<pre><code>  TextView   EditText
       Button
  TextView   EditText
        Button
   TextView   EditText
         Button
  TextView   EditText
        Button
  ..........
</code></pre>

<p>I have tried using layout params but I am getting weird results.
Here is my code,</p>

<pre><code> RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.linearlayoutid);
    final TextView[] myTextViews = new TextView[41];
    for (int i = 0; i &lt; 41; i++) {
        // create a new textview
        rowTextView = new TextView(this);
        RelativeLayout.LayoutParams paramsA = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        paramsA.addRule(RelativeLayout.RIGHT_OF, rowTextView.getId());
        rowTextView.setId(i);
        // add the textview to the layout
        relativeLayout.addView(rowTextView, paramsA);
        myTextViews[i] = rowTextView;

    }
</code></pre>

<p>For Edit Text..</p>

<pre><code>    final EditText[] editTextarray = new EditText[41];
    for (int i = 0; i &lt; 41; i++) {
        // create a new textview
        final EditText editText = new EditText(this); 
        RelativeLayout.LayoutParams paramsB = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
         editText.setText("edit");
        editText.setCursorVisible(true);
        relativeLayout.addView(editText, paramsB);
        editTextarray[i] = editText;

    }
</code></pre>

<p>I have applied layout_params like this but it didn't help. Any help would be great!! Thanks</p>