Как я могу добиться поведения «wrap_content» для элементов внутри LazyHorizontalGrid в составлении?Android

Форум для тех, кто программирует под Android
Ответить
Гость
 Как я могу добиться поведения «wrap_content» для элементов внутри LazyHorizontalGrid в составлении?

Сообщение Гость »


I'm build a layout in compose that contains a LazyHorizontalGrid with 2 rows of cards, let's say:

Код: Выделить всё

LazyHorizontalGrid(     rows = GridCells.Fixed(2),     contentPadding = PaddingValues(horizontal = 16.dp),     modifier = Modifier         .fillMaxWidth()         .aspectRatio(2F) //Workaround that I found to try to limit LazyHorizontalGrid Height ) {     item(5){         Card {             Column {                 Text(text = stringResource(id = R.string.item_title))                 Spacer(modifier = Modifier.height(12.dp))                 Image(painter = painterResource(id = R.drawable.item_image), contentDescription = null )             }         }     } } 
When I Fix it in 2 rows, the LazyHorizontalGrid changes the items height to half of the screen remaining height. In other words, it fills all the remaining height.

I placed a aspect ratio to try to limit the height of my items (by limiting the height of LazyHorizontalGrid itself). There will be other elements below the LazyHorizontalGrid.

How Can I achieve "wrap_content" behaviour for item's height inside LazyHorizontalGrid?

Things I tried:

Источник: https://stackoverflow.com/questions/781 ... lgrid-in-c
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»