我正在尝试通过绘制具有可变行高的表来表示电视节目时间表,以表示放映时间。问题是行高不会受到影响。所有行都有子项的高度。一些忠告?

码:

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


这是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


因此,我认为区别应该是显而易见的。但事实并非如此。

最佳答案

您是否尝试过nx_table.addView(tableRw, new LayoutParams(LayoutParams.MATCH_PARENT,tableRw.getChildAt(0).getHeight()+Math.round((timeDifference)*dpScale+0.5f)));
或使用以下命令:ViewGroup.addView(view,w,h)

10-01 06:40