【发布时间】:2019-03-27 21:49:37
【问题描述】:
所以我有这个界面,我在单击按钮时将新项目添加到 TableLayout。 See this picture
如上图所示,问题在于,不是在第三列顶部添加新项目,而是在第三列中将其作为新行添加。所以当listsize大于5时,新项目应该在第三列的第二列中添加线性。我只能通过添加新行来解决它。我不知道如何以一种好的方式解决这个问题。
这里是代码
fun addPlayerToTable(player: String) {
//Create new Row and TextView
val newRow = TableRow(this)
val newText = TextView(this)
var layoutParams = TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT)
//Set text on ViewText
newText.text = player
if(players.size > 5){
layoutParams.column = 2
}else {
layoutParams.column = 1
}
//Add TextViews and Rows dynamically
newRow.addView(newText, layoutParams)
table!!.addView(newRow)
}
【问题讨论】:
标签: android kotlin tablelayout