I'm trying to translate the following layout to Compose:
As you can see, the text on the left can be long, but it's allowed to wrap - the important thing is that it leaves enough space for the text on the right to be rendered. Here's what it looks like in XML:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout"
>
<TextView
android:id="@+id/stock_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/holding_quantity"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Vanguard Total Stock Market Index Fund ETF Shares"
/>
<TextView
android:id="@+id/holding_quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="?attr/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="10"
/>
</merge>
I'm struggling to find the right Row configuration that would work:
@Composable fun HoldingView() {
Row {
val typography = MaterialTheme.typography
Text("Vanguard Total Stock Market Index Fund ETF Shares", style = typography.body1)
Spacer(Modifier.preferredWidth(16.dp))
Text("10", style = typography.h4, color = MaterialTheme.colors.secondary)
}
}
Without any extra modifiers, this simply pushes the text on the right out of bounds:
Things I've tried without any luck:
- Playing with various
Arrangementoptions, such asSpaceBetween - Assigning a
Modifier.weight(1f)to the secondText
Neither of these had any effect on how the views are laid out. Is there a configuration that would work for this use case?


