Android dynamic interface tablerow
===

I am developing an app that creates a dynamic interface according to a string set by the user.

The only thing i've got in my XML file, is a scrollview, the rest is in java.

    ScrollView sv = (ScrollView)findViewById(R.id.sv);
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    TableLayout tl = new TableLayout(this);
    TableRow[] tr = null;

Then i desipher a string, which will tell me how many buttons i need to add. Next to each button should be a textview.

So in a for-loop, i create the buttons and the textviews, and add them to the tablerow, which i add to the tablelayout, which i add to the linearlayout which i add to the scrollview.


My problem is: i want the buttons to be, say 200dp wide, followed by the textview - but it takes the width from WRAP_CONTENT. Setting the size of the button with RelativeLayout and SetLayoutParams, does not work when i add it to the tablerow.

    final float scale = getBaseContext().getResources().getDisplayMetrics().density;
    	       		int pixels = (int) (200 * scale + 0.5f);
    	       		
    	       		
    	       		RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
    	       	            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    	       		rel_btn.height = pixels;
    	       		rel_btn.width = pixels;
    btn.setLayoutParams(rel_btn);

    tr[i].addView(btn);
    tr[i].addView(tv);
    tl.addView(tr[i]);

Does anyone have an idea on how to fix my problem with the tablelayout?

I've read that nested linearlayouts might be a different approach, but i cant seem to find any java examples, only XML - and i need it to be dynamic. 