Sunday, 18 July 2021

android gridlayout row and column not match the result

i want to create a gridlayout like this enter image description here

here is my setting from server

 items.add(listOf(4, 3, 0, 0)) -> start at x: 0 - y:0 expand horizontal : 4, vertical 3
 items.add(listOf(1, 1, 0, 3)) -> start at x: 0 - y:3 expand horizontal : 1, vertical 1
 items.add(listOf(1, 1, 1, 3)) -> start at x: 1 - y:3 expand horizontal : 1, vertical 1
 items.add(listOf(1, 1, 2, 3)) -> start at x: 2 - y:3 expand horizontal : 1, vertical 1
 items.add(listOf(1, 1, 3, 3)) -> start at x: 3 - y:3 expand horizontal : 1, vertical 1           

And here is my code to draw table:

private fun populateTable(){
        val items = AppUtil.getListItemsForGroupLayout(layoutCode)
        val totalRows = AppUtil.getRowOrColumns(layoutCode) -> 4 rows
        val totalCols = AppUtil.getRowOrColumns(layoutCode) -> 4 columns

        tableView.columnCount = totalCols
        tableView.rowCount = totalRows

        items.forEach {
            val params = GridLayout.LayoutParams()
            params.width = 0
            params.height = 0

            params.rowSpec = GridLayout.spec(it[3], it[1].toFloat())
            params.columnSpec = GridLayout.spec(it[2], it[0].toFloat())

            val view = TextView(this@CallScreen)
            view.text = "${it[3]} - ${it[2]} - ${it[1]} - ${it[0]}"
            view.setBackgroundColor(Int.randomColor())
            view.layoutParams = params
            tableView.addView(view)
        }
    }

But the result is not the same:

enter image description here

Can someone tech me the problem? Thanks



from android gridlayout row and column not match the result

No comments:

Post a Comment