Status Update
Comments
xx...@gmail.com <xx...@gmail.com> #2
Update
I found GridCells.Fixed calculates cell size equally each items. Therefore, behavior like SpaceAround
is correct.
However, each items are always arranged like Arrangement.Start
when Density.calculateCrossAxisCellSizes
returns value as sum of cells smaller than grid width.
an...@elkroom.com <an...@elkroom.com> #3
Since LazyVerticalGrid
will not call Density.arrange()
, so is there any solution to arrange like space between in LazyVerticalGrid
?
an...@google.com <an...@google.com>
an...@google.com <an...@google.com> #4
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit b79eaa2f9c0171e192dd14a8e958a3b0a1920d04
Author: Andrei Shikov <ashikov@google.com>
Date: Tue Mar 21 23:29:25 2023
Support arrangement for LazyGrid cells
Update grid measure logic to support custom arrangements of columns in vertical grid or rows in horizontal one.
Test: LazyGrid tests
Fixes: 235121277
Fixes: 267942510
Relnote: """Added support for fixed size cells in LazyGrid and arranging them with cross axis arrangement."""
Change-Id: I83ed9c6fa41d500ab049726b85373fade65a7ccc
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/ListDemos.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyArrangementsTest.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/lazy/grid/LazyGridTest.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/grid/LazyGrid.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/grid/LazyGridDsl.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/grid/LazyGridMeasuredLine.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/grid/LazyGridMeasuredLineProvider.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/lazy/staggeredgrid/LazyStaggeredGridCells.kt
na...@google.com <na...@google.com> #6
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.5.0-alpha02
da...@gmail.com <da...@gmail.com> #7
as...@google.com <as...@google.com> #8
Arrangement.SpaceBetween
is supported and should work as expected.
Make sure to use GridCells.FixedSize
to allow space for arrangement. Other types of GridCells
take all available space by default, which might cause it to appear differently.
mu...@gmail.com <mu...@gmail.com> #9
This doesn't solve the OP.
I need Fixed
with Arrangement.SpaceBetween
. Currently it just stretches Fixed.count
amount without adding SpaceBetween.
as...@google.com <as...@google.com> #10
Fixed
is always stretched to fill all available space (and fills in spacing from arrangement in between). You want to use FixedSize
to ensure there's some space left instead.
le...@gmail.com <le...@gmail.com> #11
@Composable
fun SimpleGrid() {
LazyVerticalGrid(
columns = GridCells.FixedSize(200.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
items(items = (1..10).toList(), span = {index -> if(index==5) {GridItemSpan(maxLineSpan)} else {GridItemSpan(1)}}) {
Button(onClick = {}, Modifier.wrapContentWidth()) {
Text(text = "$it")
}
}
}
}
an...@google.com <an...@google.com> #12
Can you please share the screenshot of what you are getting with this code and explain what behavior do you expect instead? Thanks
Description
Jetpack Compose version: 1.2.0-beta02
Jetpack Compose component used: LazyVerticalGrid
Android Studio Build: Android Studio Dolphin | 2021.3.1 Beta 2
Kotlin version: 1.6.21
Steps to Reproduce or Code Sample to Reproduce:
I expect grid items are arranged by horizontalArrangement property. However, these items are always arranged like
SpaceAround
.This may be caused by
Density.arrange
inArrangement.Horizontal
doesn't called bycalculateItemsOffsets
inLazyGridMeasure.kt
when VerticalGrid.Is anything update planned?