Vertical Line Separator with TextView
Drawing a vertical line
Update (September 2026): vertical dividers with Material 3 and Jetpack Compose
An empty View with a fixed width works, but it does not follow your theme and it is easy to get wrong when the row height changes. Both the Material library and Compose now ship a proper divider.
1. MaterialDivider in XML
Add com.google.android.material:material and use MaterialDivider. For a vertical line, give it a fixed width and a height of 0dp constrained between the top and bottom of its parent (ConstraintLayout), so it always matches the height of the text next to it:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Followers"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/divider"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.divider.MaterialDivider
android:id="@+id/divider"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@id/left"
app:layout_constraintBottom_toBottomOf="@id/left"
app:layout_constraintStart_toEndOf="@id/left"
app:layout_constraintEnd_toStartOf="@id/right" />
<TextView
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Following"
app:layout_constraintStart_toEndOf="@id/divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can change the color with app:dividerColor and, for a horizontal line, the thickness with app:dividerThickness.
2. Jetpack Compose
Compose has VerticalDivider (Material 3). Put it inside a Row and give the row IntrinsicSize.Min as its height, otherwise the divider would try to fill the whole screen height:
@Composable
fun StatsRow() {
Row(
modifier = Modifier
.fillMaxWidth()
.height(IntrinsicSize.Min),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Followers",
modifier = Modifier.weight(1f),
textAlign = TextAlign.Center
)
VerticalDivider(
thickness = 1.dp,
color = MaterialTheme.colorScheme.outlineVariant
)
Text(
text = "Following",
modifier = Modifier.weight(1f),
textAlign = TextAlign.Center
)
}
}
Use HorizontalDivider for a horizontal line. On older Material 3 versions the composable is called Divider.
Which one should you use?
- XML/View app:
MaterialDividerinside a ConstraintLayout (or a horizontal LinearLayout with weights). - Compose app:
VerticalDividerinside aRowwithIntrinsicSize.Min. - Old code: the empty
Viewwith a background color still works fine for simple cases.



Comments
Post a Comment