2011-12-30 30 views
4

我動態地將兩列的行添加到表中。其中一列包含將分散在多行中的文本。我已經爲textview的佈局參數添加了重量,因此它不再在屏幕外出現,但似乎只限於表格中顯示的兩行半,無論多行文本多長時間。該表只是在xml中定義的,其他一切都是以編程方式完成的。Android:Tablerow多行textview垂直裁剪

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); 

我該如何解決這個垂直裁剪問題? 截圖如下問題:

Here is the link showing the problem

+0

將此用於paramsText:'TableRow.LayoutParams paramsText = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,TableRow.LayoutParams.WRAP_CONTENT);' – 2011-12-31 15:11:43

回答

1

我已經找到了問題的根源。第一列值textsize製作多行文本剪輯。如果我減小文本大小,問題就會消失。 我無法解釋爲什麼。

0

我將在此放入的另一個答案:Android以非直觀的方式測量表格行高度。如果您有2個TextView(s),一個用於TableRow的每一列,則需要確保爲第一個TextView設置的頂部和底部填充設置與第二個TextView的設置相同,否則您將獲得內容等奇怪的內容裁剪和第二個TextView的奇怪定位。