2012-06-21 101 views
0

我試圖通過繪製一個表變量行高,表示顯示持續時間的某種電視時間表。問題是行高不受影響。所有行都具有子項目的高度。一些忠告?Android - 在TableRow上設置固定高度似乎沒有工作

代碼:

for(int i=0;(i+1)<DownloadInfo.nextTitle.size();i++){ 

    // Create row 
    tableRw = new TableRow(currentContext); 
    tableRw.setPadding(0, 0, 0, Math.round(5*dpScale+0.5f)); 
    nx_table.addView(tableRw); 

    // Create and add time label 
    tableTv = new TextView(currentContext); 
    tableTv.setPadding(0, 0, Math.round(5*dpScale+0.5f), 0); 
    tableTv.setText(outFormater.format(DownloadInfo.nextTime.get(i))); 
    tableTv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT)); 
    tableRw.addView(tableTv); 

    // Create and add title label 
    tableTv = new TextView(currentContext); 
    tableTv.setText(DownloadInfo.nextTitle.get(i)); 
    tableTv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT)); 
    tableRw.addView(tableTv); 

    // Modify row height 
    long timeDifference = (DownloadInfo.nextTime.get(i+1).getTime()-DownloadInfo.nextTime.get(i).getTime())/200000; 
    tableRw.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,tableRw.getChildAt(0).getHeight()+Math.round((timeDifference)*dpScale+0.5f))); 
    Log.d("RPod_MainActivity","Height of row"+i+": "+tableRw.getChildAt(0).getHeight()+Math.round((timeDifference)*dpScale+0.5f)); 
} 

這裏OS的logcat的輸出:

06-21 23:02:12.675: DEBUG/RPod_MainActivity(27189): Height of row0: 032 
06-21 23:02:12.679: DEBUG/RPod_MainActivity(27189): Height of row1: 029 
06-21 23:02:12.679: DEBUG/RPod_MainActivity(27189): Height of row2: 043 
06-21 23:02:12.683: DEBUG/RPod_MainActivity(27189): Height of row3: 038 
06-21 23:02:12.687: DEBUG/RPod_MainActivity(27189): Height of row4: 025 
06-21 23:02:12.691: DEBUG/RPod_MainActivity(27189): Height of row5: 022 
06-21 23:02:12.691: DEBUG/RPod_MainActivity(27189): Height of row6: 044 
06-21 23:02:12.695: DEBUG/RPod_MainActivity(27189): Height of row7: 034 
06-21 23:02:12.695: DEBUG/RPod_MainActivity(27189): Height of row8: 040 
06-21 23:02:12.699: DEBUG/RPod_MainActivity(27189): Height of row9: 013 
06-21 23:02:12.699: DEBUG/RPod_MainActivity(27189): Height of row10: 067 
06-21 23:02:12.703: DEBUG/RPod_MainActivity(27189): Height of row11: 059 
06-21 23:02:12.703: DEBUG/RPod_MainActivity(27189): Height of row12: 05 
06-21 23:02:12.707: DEBUG/RPod_MainActivity(27189): Height of row13: 017 
06-21 23:02:12.707: DEBUG/RPod_MainActivity(27189): Height of row14: 032 
06-21 23:02:12.710: DEBUG/RPod_MainActivity(27189): Height of row15: 04 
06-21 23:02:12.714: DEBUG/RPod_MainActivity(27189): Height of row16: 02 
06-21 23:02:12.714: DEBUG/RPod_MainActivity(27189): Height of row17: 040 
06-21 23:02:12.718: DEBUG/RPod_MainActivity(27189): Height of row18: 049 
06-21 23:02:12.718: DEBUG/RPod_MainActivity(27189): Height of row19: 052 
06-21 23:02:12.722: DEBUG/RPod_MainActivity(27189): Height of row20: 04 
06-21 23:02:12.722: DEBUG/RPod_MainActivity(27189): Height of row21: 041 
06-21 23:02:12.722: DEBUG/RPod_MainActivity(27189): Height of row22: 032 
06-21 23:02:12.726: DEBUG/RPod_MainActivity(27189): Height of row23: 016 
06-21 23:02:12.730: DEBUG/RPod_MainActivity(27189): Height of row24: 07 
06-21 23:02:12.730: DEBUG/RPod_MainActivity(27189): Height of row25: 026 
06-21 23:02:12.730: DEBUG/RPod_MainActivity(27189): Height of row26: 050 
06-21 23:02:12.734: DEBUG/RPod_MainActivity(27189): Height of row27: 032 

所以,我覺得差異應該是可見的。但事實並非如此。

回答

1

你嘗試nx_table.addView(tableRw, new LayoutParams(LayoutParams.MATCH_PARENT,tableRw.getChildAt(0).getHeight()+Math.round((timeDifference)*dpScale+0.5f))); 或使用這一個:ViewGroup.addView(view,w,h)

+1

感謝。我相反​​地設置了兒童TextViews的高度,現在相應地設置了高度。 –