TextView does not expand to fit TableRow height

How to stretch a TextView to fill the entire height of a TableRow ? Here is a screenshot of what I'm getting right now,

I want the TextView expand using TableRow .

This is how I create the line:

 row = new TableRow(this); desc = new TextView(this); desc.setBackgroundResource(R.drawable.borders); desc.setTypeface(Typeface.SERIF, Typeface.BOLD); desc.setText("Production Date"); desc.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT)); String date = gendataObj.getString("date"); text = new TextView(this); text.setBackgroundResource(R.drawable.borders); text.setText(date); text.setGravity(Gravity.LEFT); text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT)); row.addView(desc); row.addView(text); table.addView(row, new TableLayout.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); 
+4
source share
1 answer

Edit:

 text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT)); 

in

 text.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); 

Because otherwise you will not specify a height (only the width), which by default will remain as WRAP_CONTENT , which will cause your TextView be as tall as the content (text).

+4
source

All Articles