KotlinLeaner
04/05/2023, 8:58 PMComposeView
by the help of documentation. I have a list which is more than 50 items to display. So I am trying to use LazyColumn
inside setContent
but it giving me error Vertically scrollable component was measured with an infinity maximum height constraints....
. I know this error when we doing nested LazyColumn
, but I am not using any component related to compose to this screen. So what should I do in here?<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="<http://schemas.android.com/apk/res/android|http://schemas.android.com/apk/res/android>"
xmlns:app="<http://schemas.android.com/apk/res-auto|http://schemas.android.com/apk/res-auto>"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/consentBanneryz">
<androidx.compose.ui.platform.ComposeView
android:id="@+id/itemComposable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
//// more item in here
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
binding.itemComposable.apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
XyzTheme {
ListView(list)
}
}
}
@Composable
fun ListView(itemList: List<Int>?
) {
AnimatedVisibility(visible = !itemList.isNullOrEmpty()) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
) {
item { Text() }
}
}
}
Error
java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
orangy
04/05/2023, 11:25 PMLucca Beurmann
04/06/2023, 4:18 AM