2012-06-21 136 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的高度,现在相应地设置了高度。 –