There is such a problem. There is a GridLayout which explicitly indicates the number of rows and columns.

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:rowCount="4" android:columnCount="4" /> 

Items are added dynamically as follows.

 GridLayout.Spec column = GridLayout.spec(value); GridLayout.Spec row = GridLayout.spec(value); GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, column); gridLayout.addView(view, params); 

The whole problem is that when adding an element to a cell with a number for example 3.3 (and it also happens when other values ​​of cells are not equal to 0.0), the addition occurs in the specified cell but the view is displayed in place of the cell 0.0 instead of your cell. After adding the second representation to the cell 0.0 (or to the neighboring cells) the grid is aligned and the elements are placed in their places, that is, the first added element starts to appear in its place (moves from the cell 0.0 to its own) and the second added element in its place The whole problem is how to implement the addition in such a way that the elements are initially displayed in the cells in which they are added, and not actually in a random place and in the course of filling the GridLayout are aligned and started to appear in their places. Moreover, all added views are the same size.

    1 answer 1

    This is a crutch, but you can consider it as a solution: you can create a filled table, just make all the cells invisible. Accordingly, as you add cells to change the visibility. See also recyclerview with gridlayoutmanager