Failure, because it is TableRowalready in the layout. If you want to add dynamically, you must create it programmatically, that is:
TableRow newRow = new TableRow(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams();
newRow.setLayoutParams(lp);
relLayout.add(newRow);
Actually TableRowshould be used internally TableLayout.
- , . xml, , (, TableRow ), :
LayoutInflater inflater =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflated = inflater.inflate(R.layout.your_layout, null);
inflated . null , . , , .
( , )
------ EDIT -----
ok , :
RelativeLayout RLayout = (RelativeLayout)findViewById(R.id.RelativeLayout);
TableRow tableRow = (TableRow)findViewById(R.id.TableRow);
for(int i = 1; i <4; i++) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View inflated = inflater.inflate(R.layout.main, tableRow);
}
TableRow.
row.xml, , main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text"
/>
</TableRow>
:
RelativeLayout RLayout = (RelativeLayout)findViewById(R.id.RelativeLayout);
for(int i = 1; i <4; i++) {
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.row, RLayout);
}
, .