Csaba Szugyiczki
10/10/2021, 4:06 PMfillMaxHeight
height, and then applying the verticalScroll
modifier on it. But if we use an inner Column, then the way it is measured is different than what we got used to using XML layouts. Setting an inner Columns height to wrapContentHeight
and applying .weight(1f)
on it only respects the weight modifier, but the wrapContentHeight
modifier is ignored. This makes the Column
cut its children.
Is there a workaround for this?
Sample code in đź§µCsaba Szugyiczki
10/10/2021, 4:06 PMCsaba Szugyiczki
10/10/2021, 4:09 PMCsaba Szugyiczki
10/10/2021, 4:11 PMCsaba Szugyiczki
10/10/2021, 4:12 PM<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:tools="<http://schemas.android.com/tools>"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ec0000"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#0000ec">
<View
android:layout_width="match_parent"
android:layout_height="900dp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Footer" />
</LinearLayout>
</ScrollView>
Csaba Szugyiczki
10/10/2021, 4:13 PMCsaba Szugyiczki
10/10/2021, 4:13 PMAlbert Chang
10/11/2021, 2:08 AMModifier.wrapContentHeight()
. It is not the same as wrap_content
in View system as it doesn't change layout size. It only controls how the content is aligned in the incoming constraints. See the doc:
If the content's measured size is smaller than the minimum height constraint, align it within that minimum height space. If the content's measured size is larger than the maximum height constraint (only possible when unbounded is true), align over the maximum height space.
Albert Chang
10/11/2021, 2:10 AMColumn(
Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.background(color = Color.Red)
) {
Text(text = "Header")
Column(
Modifier.background(color = Color.Blue)
) {
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(900.dp)
)
}
Spacer(modifier = Modifier.weight(1f))
Text(text = "Footer")
}
Csaba Szugyiczki
10/11/2021, 5:56 AM