I have an Add Shopping List item Jetpack Compose screen which contains several TextField inputs and an image container at the bottom. The screen overflows at the bottom and is cut off. How can I scroll the screen?
3 Answers
EDIT: October 2023
At some point along the way this was changed and the old solution does not work anymore. The solution to this question is now:
val scrollState = rememberScrollState() ... Column( // or whatever your parent composable is modifier = Modifier .verticalScroll(state = scrollState) ) { ... } Old solution
Add Modifier.scrollable(..) to the container that you wish to make scrollable. Code would be something like this:
val scrollState = rememberScrollState() ... Box( // or whatever your parent composable is modifier = Modifier .scrollable(state = scrollState, orientation = Orientation.Vertical) ) { ... } Of course, there are other Modifier methods for making composables scrollable that might fit better for your case.
3 Comments
Chirag Thummar
this does not work for me with compose version 1.3.3
Bipin Bharti
same here not working
Manishoaham
Box(modifier = Modifier.verticalScroll(rememberScrollState())) { ... also worksYou can use the modifier verticalScroll on your container to achieve this.
Column( modifier = Modifier.verticalScroll(state = rememberScrollState()) ) { ... } 1 Comment
Jeremy Caney
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?