|
3 | 3 | All grid layout composables take a cell strategy parameter called `SimpleGridCells`. |
4 | 4 | `SimpleGridCells` defines the number of cells and the size of each cell. |
5 | 5 |
|
6 | | -There are 2 types of cell strategy, `Fixed` and `Adaptive`. |
7 | | -They are similar to LazyGrid's `Fixed` and `Adaptive`. |
| 6 | +There are several types of cell strategy, `Fixed`, `Adaptive` and `FixedSize`. |
| 7 | +They are similar to LazyGrid's `GridCells.Fixed`, `GridCells.Adaptive` and `GridCells.FixedSize`. |
8 | 8 |
|
9 | 9 | ## Fixed |
10 | 10 |
|
@@ -94,9 +94,51 @@ And each cells will have 1/3 of 400dp (about 133.333dp) width or height. |
94 | 94 | If the grid size is expanded to 600dp, the number of cells on each line will be changed to 5 |
95 | 95 | and each cell's size will be 120dp. |
96 | 96 |
|
| 97 | +## FixedSize |
| 98 | + |
| 99 | +`SimpleGridCells.FixedSize` is a cell strategy for as many cells as possible with exact size. |
| 100 | + |
| 101 | +The API of `FixedSize` looks like this: |
| 102 | + |
| 103 | +```kotlin |
| 104 | +class FixedSize( |
| 105 | + private val size: Dp, |
| 106 | + private val fill: Boolean = true |
| 107 | +) : SimpleGridCells |
| 108 | +``` |
| 109 | + |
| 110 | +There is a parameter called `size`. This is the size of each cell should have. |
| 111 | +The `size` must be a positive size. If the size is 0 or below, it occurs an exception. |
| 112 | +If the `size` is bigger than container's size, the cell will have the same size to the container. |
| 113 | + |
| 114 | +!!! note |
| 115 | + For information about `fill` parameter, read [Fill Option](#fill-option) section. |
| 116 | + |
| 117 | +For example, a grid has 400dp width or height and `FixedSize(120.dp)` is applied. |
| 118 | + |
| 119 | +```kotlin |
| 120 | +HorizontalGrid( |
| 121 | + rows = SimpleGridCells.FixedSize(120.dp), |
| 122 | + modifier = Modifier.height(400.dp) |
| 123 | +) { /* content */ } |
| 124 | + |
| 125 | +VerticalGrid( |
| 126 | + columns = SimpleGridCells.FixedSize(120.dp), |
| 127 | + modifier = Modifier.width(400.dp) |
| 128 | +) { /* content */ } |
| 129 | +``` |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +The grid will have 3 cells on each line and the remaining space will not be used. |
| 134 | +If the grid size is expanded to 600dp, the number of cells on each line will be changed to 5. |
| 135 | + |
| 136 | +In other case, `FixedSize(300.dp)` for `VerticalGrid(Modifier.width(200.dp))` means that there |
| 137 | +will be only one column and the cell will have 200dp width. |
| 138 | + |
97 | 139 | ## Fill Option |
98 | 140 |
|
99 | | -Both `Fixed` and `Adaptive` have a optional parameter named `fill`. |
| 141 | +All cell strategy classes have a optional parameter named `fill`. |
100 | 142 | The `fill` parameter determines that grid's item composable should fill grid cell's size. |
101 | 143 |
|
102 | 144 | When `fill` is true, grid layout forces item composable to have width or height to fit cell's maximum width or height. |
|
0 commit comments