0

I have a Column and inside the Column, I have a Spacer with a specific size and a LazyColumn. What is happening now is that when I want to scroll, First LazyColumn starts to scrolling, and when it reaches the end, the Column starts scrolling to the end.

What I want is that first the Column starts to scroll and when it reaches the end, My LazyColumn starts to scroll.

This is my sample code

 Column(
            modifier = Modifier
                .fillMaxHeight()
                .verticalScroll(scrollState),
        ) {
            Spacer(modifier = Modifier.height(300.dp))
            LazyColumn(
                modifier = Modifier
                    .height(LocalConfiguration.current.screenHeightDp.dp)
                    .fillMaxSize(),
            ) {
                items(50) { item ->
                    Text(modifier = Modifier.height(40.dp), text = "ITEM NUMBER: $item")
                }
            }
        }
1
  • You can't add Column with vertical scroll and lazy colum. Commented May 16, 2023 at 17:51

2 Answers 2

1

Add your Spacer code inside the LazyColumn as one of the item and remove Column.

LazyColumn(modifier = Modifier.fillMaxSize()) {
            item {
                Spacer(modifier = Modifier.height(300.dp))
            }
            items(50) { item ->
                Text(modifier = Modifier.height(40.dp), text = "ITEM NUMBER: $item")
            }
        }
Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure, what your ultimate goal is, if you are going to have some additional content in the column or not but for this particular example, I don't think nested scrolling is needed :)

The code below should behave as you wanted. It will scroll the content including the spacer which is now replaced by the content padding. Hope this helps! :)

LazyColumn(
    modifier = Modifier.fillMaxSize(),
    contentPadding = PaddingValues(top = 300.dp),
) {
    items(50) { item ->
        Text(
            modifier = Modifier.height(40.dp),
            text = "ITEM NUMBER: $item"
        )
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.