Is it possible to define different height for the items in ScalingLazyColumn? I have a head element,...
y
Is it possible to define different height for the items in ScalingLazyColumn? I have a head element, which shall have only the half height of the rest items. My SLC sets by default all items to the same height.
y
It shouldn't. Put a border on it and you'll see. But ListHeader enforces a min height or padding.
Try with a SLC with spacers and Border ro show
y
It turns out, that the head item in SLC is a Row composable with all child elements having no explicit heights defined. The head item adopts the height to the other items in SLC. As I tried to fill head item with half of MaxHeight in Row composable, it doesn’t work as I imagined using
.fillMaxHeight(0.5f)
Copy code
ScalingLazyColumn(...) {
    item {
        Row( modifier = Modifier
                  .fillMaxWidth()
                  .fillMaxHeight(0.5f)
        ) {
          Text(text = "head text")
          ...
It does work after I set an explicit size of a child element of Row composable in the head item.
Copy code
ScalingLazyColumn(...) {
    item {
        Row( modifier = Modifier
                  .fillMaxWidth() 
        ) {
           Text(modifier = Modifier
                    .size(24.dp),                        
               text = "head text")
           ...
Thanks for the hint to put border and spacers in SLC, it does help me to see the structure better in preview tool. The Layout Inspector doesn’t really help IMO to debug, if the structure gets complicated.
y
I'm not sure I follow exactly what you are attempting. But have you tried
fillParentMaxHeight
it's from ScalingLazyListItemScope.
y
I try to make a list of Chips and a head element with a text and icon in side using SLC, the head element shall having the half height of the Chips height.
y
Do the chips vary based on content? Or can you just measure them once and apply that size (24)?
y
In my case the chips doesn’t vary in height, I can measure them. The apply size does works. I thought, I can do something like using
.height(IntrinsicSize.Min)
,
.fillMaxHeight(0.5f)
to get some relativ height from SLC and its items max height. The
fillParentMaxHeight
also doesn’t work, it just fill more height than
fillMaxHeight(0.5f)
y
I'm not sure I did help, but no problem.
y
@yschimke Your tip for the
fillParentMaxHeight
from ScalingLazyListItemScope actually does work. In my case the parent height of SLC item seams to be the screen height. I need to calc the relative fraction differently.
fillParentMaxHeight(0.15f)
does the trick.
y
Nice. But I'd expect chips to be a stable size, so figured a hardcoded value isn't so bad. Up to you.