Android: multiline text view in Tablerow vertically

I am dynamically adding rows with two columns to the table. One of the columns contains text that will be spread over several lines. I added weight according to the layout options for text viewing so that it no longer loops off the screen, but it seems to be limited to two and half lines displayed in the table, no matter how long the multiline text lasts. The table is defined only in xml and everything else is done programmatically.

TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT); TableRow.LayoutParams paramsStar = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); paramsStar.setMargins(0,0,40,0); TableRow.LayoutParams paramsText = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT, (float)1.0); TableRow tr = new TableRow(this); tr.setLayoutParams(rowParams); TextView viewStar = new TextView(this); viewStar.setTextSize((float) 30.0); viewStar.setText("*"); viewStar.setLayoutParams(paramsStar); viewStar.setTypeface(Typeface.DEFAULT_BOLD, 2); TextView viewText = new TextView(this); viewText.setText("Long multiline text piece"); //<--- Here the long text goes viewText.setLayoutParams(paramsText); tr.addView(viewStar); tr.addView(viewText); table.addView(tr, rowParams); 

How to fix this vertical crop? Screenshot below:

Here is a link showing the problem

+4
source share
2 answers

I found the root of the problem. The first text values ​​of the columns made a multi-line text clip. If I reduce the text, the problem will disappear. I can’t explain why.

+1
source

Another answer that I will take here: Android measures the height of a table table very unintuitively. If you have 2 TextView (s), one for each TableRow column, you need to make sure that all the top and bottom padding that you set for the first TextView is set the same for the second TextView or you get weird things like clipping content and weird positioning of the second TextView.

0
source

Source: https://habr.com/ru/post/1388617/


All Articles