gpt4 book ai didi

java - Android - 在 TableRow 上设置固定高度似乎不起作用

转载 作者:行者123 更新时间:2023-12-01 15:19:34 25 4
gpt4 key购买 nike

我正在尝试做某种电视节目表,通过绘制一个具有可变行高的表格来表示节目持续时间。问题是行高不受影响。所有行都有子项的高度。有什么建议吗?

代码:

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)

关于java - Android - 在 TableRow 上设置固定高度似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11146783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com