Thats my tab.
I want to align it to center of the screen. (horizontal and vertical)
The table is created dynamically from java.
I tried set
TableLayout t1 = (TableLayout)findViewById(R.id.maintable);
t1.setGravity(Gravity.CENTER);
But it align it only from top.
public class TabActivity extends Activity {
Trny t = Trny.getInstance();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab);
TableLayout t1 = (TableLayout)findViewById(R.id.maintable);
t1.setGravity(Gravity.CENTER);
// first row of table
TableRow tr = new TableRow(this);
TextView place = new TextView(this);
poradi.setText("P" );
poradi.setPadding(10, 5, 10, 5);
tr.addView(place);
TextView nameOfTeam = new TextView(this);
nazTymu.setText("Nazev" );
nazTymu.setPadding(10, 5, 10, 5);
tr.addView(nameOfTeam);
TextView matchesPlayed = new TextView(this);
odehraneZapasy.setText("Z" );
odehraneZapasy.setPadding(10, 5, 10, 5);
tr.addView(matchesPlayed);
TextView numbefOfWins = new TextView(this);
pocetVyher.setText("V" );
pocetVyher.setPadding(10, 5, 10, 5);
tr.addView(numbefOfWins);
TextView numberOfTies = new TextView(this);
pocetRemiz.setText("R" );
pocetRemiz.setPadding(10, 5, 10, 5);
tr.addView(numberOfTies);
TextView numberOfLoses = new TextView(this);
pocetProher.setText("P" );
pocetProher.setPadding(10, 5, 10, 5);
tr.addView(numberOfLoses);
TextView goalsScored = new TextView(this);
skorePlus.setText("VG" );
skorePlus.setPadding(10, 5, 10, 5);
tr.addView(goalsScored);
TextView goalsGained = new TextView(this);
skoreMinus.setText("OG" );
skoreMinus.setPadding(10, 5, 10, 5);
tr.addView(goalsGained);
TextView numberOfPoints = new TextView(this);
pocBodu.setText("B" );
pocBodu.setPadding(10, 5, 10, 5);
tr.addView(numberOfPoints);
t1.addView(tr);
//more rows dynamically created from java
}
}
XML file
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/maintable" >
</TableLayout>
How can i achieve this? Thanks guys.
change your layout XML to this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/maintable"
android:layout_centerInParent="true" >
</TableLayout>
</RelativeLayout>
Related
I have a dynamic table layout like this:
<LinearLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="10sp"
android:textColor="#color/accent_material_light"
android:id="#+id/tabTitle"/>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:stretchColumns="*"
android:shrinkColumns="*"
android:layout_below="#+id/tabTitle"
>
</TableLayout>
</LinearLayout>
now i want to set width of rows as same as the header row width in dynamic table layout. And i want to set the column values should be equally distribute according to the different screen sizes.
eg. I have 4 columns say Id, name, subject name and subject mark. These values should get equal space even if they are in different screen size devices.
But the values coming under these columns should have their respective header width.
private void buildTable() {
TableRow tr_head = new TableRow(getActivity());
// tr_head.setId(10);
tr_head.setBackgroundColor(Color.GRAY);
tr_head.setLayoutParams(new TableLayout.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
tr_head.setGravity(Gravity.CENTER);
tr_head.setWeightSum(4f);
TextView label_id = new TextView(getActivity());
// label_date.setId(20);
label_id.setText("ID");
label_id.setTextColor(Color.WHITE);
label_id.setPadding(5, 5, 5, 5);
tr_head.addView(label_id);// add the column to the table row here
TextView label_name = new TextView(getActivity());
label_name .setText("Student Name"); // set the text for the header
label_name .setTextColor(Color.WHITE); // set the color
label_name .setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(label_name ); // add the column to the table row here
TextView label_sub = new TextView(getActivity());
label_sub .setText("Subject Name"); // set the text for the header
label_sub .setTextColor(Color.WHITE); // set the color
label_sub .setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(label_sub ); // add the column to the table row here
TextView label_mark = new TextView(getActivity());
label_mark.setText("Subject Mark"); // set the text for the header
label_mark.setTextColor(Color.WHITE); // set the color
label_mark.setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(label_mark); // add the column to the table row here
tl.addView(tr_head, new TableLayout.LayoutParams(
0,
TableRow.LayoutParams.WRAP_CONTENT, 1f));
.....
// Create the table row
TableRow tr = new TableRow(getActivity());
tr.setBackground(getResources().getDrawable(
R.drawable.row_color));
tr.setLayoutParams(new TableRow.LayoutParams(
0,
TableRow.LayoutParams.WRAP_CONTENT, 1f));
//Create two columns to add as table data
TextView labelid = new TextView(getActivity());
labelid .setText(id);
labelid .setPadding(2, 0, 5, 0);
labelid .setTextColor(Color.WHITE);
tr.addView(labelid );
TextView labelname = new TextView(getActivity());
labelname .setText(name);
labelname .setTextColor(Color.WHITE);
tr.addView(labelname );
TextView labelSub = new TextView(getActivity());
labelSub .setText(sub);
labelSub .setTextColor(Color.WHITE);
tr.addView(labelSub );
TextView labelSubMark = new TextView(getActivity());
labelSubMark .setText("mark");
labelSubMark .setTextColor(Color.WHITE);
tr.addView(labelSubMark);
// finally add this to the table row
tl.addView(tr, new TableLayout.LayoutParams(
0,
TableRow.LayoutParams.WRAP_CONTENT, 1f));
} while (c.moveToNext());
}
}
}
}
please help anyone...tried everything but all in vain.
I am currently working on an android app where I select a customer in an activity, it retrieves all records pertaining to that customer and displays them in a table layout in a new activity.
The problem arises when I go back to the previous activity and select a different customer, the new records are added behind the records of the previous customer (meaning the previous table layout entries are not deleted when I press the back button and go to select a new customer).
I've tried 2 solutions:
tl = (TableLayout) findViewById(R.id.maintable);
tl.removeAllViewsInLayout();
and
layout = (RelativeLayout)findViewById(R.id.layout1);
tl = (TableLayout) findViewById(R.id.maintable);
int count=tl.getChildCount();
for(int i=0;i<count;i++)
tl.removeView(layout.getChildAt(i));
Both these solutions do not work for me as the new data is still being added behind the existing data.
Could anyone suggest me a different solution that could work?
Also I am attaching the entire code.
OutstandingBills.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_outstanding_bills);
layout = (RelativeLayout)findViewById(R.id.layout1);
tl = (TableLayout) findViewById(R.id.maintable);
tl.removeAllViewsInLayout();
int count=tl.getChildCount();
for(int i=0;i<count;i++)
tl.removeView(layout.getChildAt(i));
addHeaders();
addData();
}
public void addHeaders(){
tr = new TableRow(OutstandingBills.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView bilDateTV = new TextView(OutstandingBills.this);
bilDateTV.setText("Date");
bilDateTV.setTextColor(Color.BLACK);
bilDateTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
bilDateTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
bilDateTV.setPadding(5, 5, 5, 0);
tr.addView(bilDateTV); // Adding textView to tablerow.
TextView billNoTV = new TextView(OutstandingBills.this);
billNoTV.setText("Bill No.");
billNoTV.setTextColor(Color.BLACK);
billNoTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
billNoTV.setPadding(5, 5, 5, 0);
billNoTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(billNoTV); // Adding textView to tablerow.
TextView dueAmtTV = new TextView(OutstandingBills.this);
dueAmtTV.setText("Amount Due");
dueAmtTV.setTextColor(Color.BLACK);
dueAmtTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
dueAmtTV.setPadding(5, 5, 5, 0);
dueAmtTV.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(dueAmtTV); // Adding textView to tablerow.
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr = new TableRow(OutstandingBills.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView divider = new TextView(OutstandingBills.this);
divider.setText("-----------------");
divider.setTextColor(Color.BLACK);
divider.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
divider.setPadding(5, 0, 0, 0);
divider.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(divider); // Adding textView to tablerow.
TextView divider2 = new TextView(OutstandingBills.this);
divider2.setText("-------------------------");
divider2.setTextColor(Color.BLACK);
divider2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
divider2.setPadding(5, 0, 0, 0);
divider2.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(divider2); // Adding textView to tablerow.
TextView divider3 = new TextView(OutstandingBills.this);
divider3.setText("-------------------------");
divider3.setTextColor(Color.BLACK);
divider3.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
divider3.setPadding(5, 0, 0, 0);
divider3.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(divider3); // Adding textView to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
public void addData(){
for (int i = 0; i < arr.size(); i++)
{
tr = new TableRow(OutstandingBills.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
bilDate = new TextView(OutstandingBills.this);
bilDate.setText(arr.get(i).toString());
bilDate.setTextColor(Color.BLACK);
bilDate.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
bilDate.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
bilDate.setPadding(5, 5, 5, 5);
tr.addView(bilDate); // Adding textView to tablerow.
bilNo = new TextView(OutstandingBills.this);
bilNo.setText(arr1.get(i).toString());
bilNo.setTextColor(Color.BLACK);
bilNo.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
bilNo.setPadding(5, 5, 5, 5);
bilNo.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(bilNo); // Adding textView to tablerow.
dueAmt = new TextView(OutstandingBills.this);
dueAmt.setText(arr2.get(i).toString());
dueAmt.setTextColor(Color.BLACK);
dueAmt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
dueAmt.setPadding(5, 5, 5, 5);
dueAmt.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
tr.addView(dueAmt); // Adding textView to tablerow.
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
OutstandingBills.xml:
<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:id="#+id/layout1"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.ashwin.projectx1.OutstandingBills">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1"
android:id="#+id/maintable" >
</TableLayout>
</ScrollView>
</RelativeLayout>
Implementing # Mr.Neo 's solution:
This is how I implemented your solution in my code:
addHeaders();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//Add view for table layout here
addData();
}
}, 2000);
But there is still no effect on the TableLayout
Screenshots:
The first time I enter the activity with a Customer name
On re-entering the activity the second time, you can see the duplicate records
Just try using tl.removeAllViews() instead of tl.removeAllViewsInLayout().
Call this method before adding views in tablelayout.
Here is the solution I am using. Using removeAllViews() and add view after seconds to completely removing. If you add immediately, some rows could not be removed. I know this is not the best solution, but it's the best for me now.
tableMainContent.removeAllViews();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//Add view for table layout here
}
}, 2000);
I would like to know if there is a way to modify the width of two columns in a table layout (with three columns in total).
The problem is that every column has the same width and a lot of space is wasted because the first two only contain an id and a date meanwhile the last one contains a multiline description.
This is the code in which the table layout is populated:
tr_head.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
tr_head.setBackgroundColor(Color.rgb(0, 230, 230));
TextView lblSystemStoricalHeaderId = new TextView(this);
lblSystemStoricalHeaderId.setText("ID ");
tr_head.addView(lblSystemStoricalHeaderId);
TextView lblSystemStoricalHeaderData = new TextView(this);
lblSystemStoricalHeaderData.setText("Data");
tr_head.addView(lblSystemStoricalHeaderData);
TextView lblSystemStoricalHeaderDescription = new TextView(this);
lblSystemStoricalHeaderDescription.setText(" Descrizione");
tr_head.addView(lblSystemStoricalHeaderDescription);
tr_head.setMinimumHeight(30);
tlSystemStorical.addView(tr_head, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
for(int i=0;i<reportList.length;i++){
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
TextView lblSystemStoricalId = new TextView(this);
lblSystemStoricalId.setText(""+reportList[i].getId()+"");
tr.addView(lblSystemStoricalId);
TextView lblSystemStoricalData = new TextView(this);
long dataC = reportList[i].getDate()*1000;
java.util.Date df = new java.util.Date(dataC);
String vv = new SimpleDateFormat("dd/MM/yyyy").format(df);
lblSystemStoricalData.setText(vv);
tr.addView(lblSystemStoricalData);
TableRow.LayoutParams tv3Params = new TableRow.LayoutParams();
tv3Params.width=0;
tv3Params.weight=1;
TextView lblSystemStoricalDescription = new TextView(this);
lblSystemStoricalDescription.setText(""+reportList[i].getReportDescription());
lblSystemStoricalDescription.setLayoutParams(tv3Params);
tr.addView(lblSystemStoricalDescription);
tr.setBackgroundResource(R.drawable.border);
tr.setMinimumHeight(40);
tlSystemStorical.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}
and this is the xml file:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scroll_view_system_description"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:id="#+id/tl_system_storical"
>
</TableLayout>
</FrameLayout>
</ScrollView>
You can set width property to 0 for TableRow children, but specify layout_weight for them. So you'd write:
float[] weights = new float[] { 0.2f, 0.2f, 0.6f};
TextView lblSystemStoricalId = new TextView(this);
lblSystemStoricalId.setLayoutParams(new TableRow.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, weights[0]))
Where 0 is no width for view (because you're using weights), and weights array contains weights for your three views.
These weights should sum up to 1, and each weight is percent of the width that the column should take. So you need to assign weights to your TableRow children - lblSystemStoricalId would get weights[0], lblSystemStoricalData would get weights[1] and lblSystemStoricalDescription would have weights[2].
I'm using a table layout with a vertical scroll view to display a huge list of Data programmaticlly. On a tablet it works with a perfect way but the problem when I run it on a phone like galaxy or nexus 1 the width of the table layout does not match the width of the screen so two or three columns are hidden I have tried all combination match_parent , wrap_content ... I used an horizontal scroll view it works but I don't think that it's a good solution
this is the xml file :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:paddingBottom="#dimen/activity_vertical_margin"
tools:context="..."
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mv_table"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginTop="50dp">
</TableLayout>
</RelativeLayout>
</ScrollView>
this is my code :
TableLayout mvtable = (TableLayout) findViewById(R.id.mv_table);
TableRow tr_head = new TableRow(this);
tr_head.setId(10);
tr_head.setBackgroundColor(Color.rgb(24,65,95));
TextView label_Date = new TextView(this);
label_Date.setId(20);
label_Date.setText("Date");
label_Date.setTextColor(Color.WHITE);
label_Date.setPadding(5, 5, 5, 5);
tr_head.addView(label_Date);
TextView label_Debit = new TextView(this);
label_Debit.setId(21);
label_Debit.setText("Débit");
label_Debit.setTextColor(Color.WHITE);
label_Debit.setPadding(5, 5, 5, 5);
tr_head.addView(label_Debit);
.....
tr_head.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
mvtable.addView(tr_head, new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
//setting data programmaticlly
int c ;
int i=1;
for (Movement mv : movementsList)
{
TableRow tr = new TableRow(this);
if (i % 2 != 0)
{
c=Color.WHITE;
tr.setBackgroundColor(Color.GRAY);}
else
{c=Color.BLACK;
}
tr.setId(100 + i);
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
TextView labelDate = new TextView(this);
labelDate.setId(200+i);
labelDate.setText(mv.getDate());
labelDate.setTextColor(c);
labelDate.setPadding(5, 5, 5, 5);
tr.addView(labelDate);
TextView labelDebit = new TextView(this);
labelDebit.setId(210+i);
labelDebit.setText(mv.getDebit());
labelDebit.setTextColor(c);
labelDebit.setPadding(5, 5, 5, 5);
labelDebit.setBackgroundColor(Color.rgb(255,174,185));
tr.addView(labelDebit);
......
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
mvtable.addView(tr, new TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
i++;
}
use LinearLayout instead of RelativeLayout it may solve your problem. because RelativeLayout overlaps one on other
I need to dynamically add some tablerows to a linearlayout in my app. I write this code:
LinearLayout tabella = (LinearLayout) findViewById(R.id.tabella_contatori);
for(int i =0; i<array_list.size(); i++){
TableRow row = new TableRow(getApplicationContext());
row.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView data = new TextView(getApplicationContext());
data.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.2f));
data.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
data.setTextColor(Color.BLACK);
data.setBackgroundColor(Color.WHITE);
data.setPadding(2, 0, 0, 0);
data.setText("asd");
row.addView(data);
tabella.addView(row);
}
}
But when I open the app nothing appens. I already check if array_list.size is bigger than 0.
How can I do?
Thanks, Mattia
The problem is in your TextView Layout Params. The type should be TableRow.LayoutParams not LinearLayout.LayoutParams.
data.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
Take Table layout and try using this in your main.xml ...
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Some Text"/>
</TableRow>
</TableLayout>
in your Activity
this.setContentView(R.layout.main);
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
/* Create a TextView to be the row-content. */
TextView data = new TextView(getApplicationContext());
data.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.2f));
data.setTextAppearance(getApplicationContext(), android.R.attr.textAppearanceMedium);
data.setTextColor(Color.BLACK);
data.setBackgroundColor(Color.WHITE);
data.setPadding(2, 0, 0, 0);
data.setText("asd");
/* Add TextView to row. */
tr.addView(data);
/* Add row to TableLayout. */
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));