When I use scalinglazycolumn (autocentring = false...
# compose-wear
l
When I use scalinglazycolumn (autocentring = false), how can I make this page automatically scroll to the top. thank you.
k
Hello, with
ScalingLazyColumn
scrolling is available out of the box. If I understood correctly the problem you need to add/increase padding for the top, so there is an actual space for scrolling. You can do this with specifying values in
contentPadding
, for example:
Copy code
ScalingLazyColumn(
    modifier = Modifier.fillMaxSize(),
    contentPadding = PaddingValues(
        top = 50.dp,
    ),
    verticalArrangement = Arrangement.Center,
    state = scalingLazyListState,
    autoCentering = false
) {
...
}
Any reason why you can’t use
autoCentering = true
(default value)? It already does all heavy lifting for you and ensures that all items properly visible in the viewport for different screen shapes/sizes. So you don’t need to specify any paddings manually.
j
What is it that autoCentering isn't giving you that you need? There are improvements coming soon, but I would like to know what else you might need.
l
thank you Kseniia shumelcyk and John Nichol. It seems that kseniia shumelcyk understands what I mean. When a page has a lot of content, I choose to use scaling lazy column. What I want to see is that when I open this page, this page should automatically interact to the top. Because users want to see the content of this page from the top.
j
I don't understand the issue, perhaps you could provide a simple example that shows the problem.As @Kseniia Shumelchyk points out you can use content padding if you have a very specific use case, but autoCentering, but you have to allow for different screen sizes yourself - autoCentering is really auto contentPadding. You control which item you want in the center of the screen with ScalingListListState initialItemOffset, you control whetherh you want the edge or center of the item to anchor the screen with anchorType. As I say perhaps an exaple of what yuu want and the code you are using would help so we can understand what the difficulty you are facing is
l
When the page opens, as shown in the video, it comes back to the top when I drag the page. I want the page to be at the top when it opens.
I solved it,John Nichol.
Copy code
val listState = rememberScalingLazyListState(initialCenterItemIndex = 0)