Anyways Today, I am going to show you guys "How to split the Android Layout Vertically". And trust me it's a very very simple. But before doing that we need to consider some scenario:-
- Just remember, its not a Rocket Science.
- We really no need to do anything like calculating the height.
- Not require to convert px, dp, sp with your device resolution.
- And last, let's get started........😇😇😏
And when we talk about displaying the information, let's take an example like if we want to display the details of a student in the detail screen of that School App.
- Name (first and last name)
- Age / DOB (Date Of Birth)
- Sex
- Profile picture on the top of the block of the detail screen
- Address
- Contact Number
- Parents Detail
- Class No
- Roll No
- Remark
- Class Teacher
- Attendance
- Bus number
- The first view is to display the profile image.
- The second view is to display a listview with image and some text.
- This second view is also inside the tab view.
Note: "Same-way before letting us start with any layout design, the first step is always to divide the layout view (if necessary) into subviews".
![]() |
| Cheers for that |
Splitting the layout into two equal part for the horizontal and vertical View
Splitting the layout into three equal part for the horizontal and vertical View
Splitting the layout into three equal part
Output for the above layout:
And like every good thing is supposed to come at its END. ↓
If you guys have any questions about Layout or any of the UI components, Please do Leave a comment below..!!
&&
If you like this article don’t forget to share it. Till then "Happy coding".
Update (September 2026): splitting the screen with ConstraintLayout and Jetpack Compose
Splitting a screen vertically (for example a profile header on top and the details below) with layout_weight inside a LinearLayout, as shown in this post, still works. Two modern options give you more control and avoid the extra nesting: a Guideline in ConstraintLayout for XML and Modifier.weight in Jetpack Compose.
1. XML: ConstraintLayout with a Guideline
A horizontal Guideline placed at 40% of the screen height splits the screen into two areas. Each area is just a view constrained to the guideline, so there is no weight calculation and no nested layout:
<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="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/split"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.4" />
<FrameLayout
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#6650A4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/split"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ScrollView
android:id="@+id/details"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/split"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Change layout_constraintGuide_percent to move the split. For a vertical split (left/right, for example on tablets) use android:orientation="vertical" on the guideline.
2. Jetpack Compose: Column with weights
In Compose the same 40/60 split is a Column whose children get a weight:
@Composable
fun SplitScreen() {
Column(modifier = Modifier.fillMaxSize()) {
Box(
modifier = Modifier
.weight(0.4f)
.fillMaxWidth()
.background(Color(0xFF6650A4)),
contentAlignment = Alignment.Center
) {
Text("Header", color = Color.White)
}
LazyColumn(
modifier = Modifier
.weight(0.6f)
.fillMaxWidth()
) {
items(20) { index ->
Text(
text = "Detail row " + index,
modifier = Modifier.padding(16.dp)
)
}
}
}
}
Use Row instead of Column for a left/right split. The weights are ratios, so weight(1f) and weight(1f) gives you an even 50/50 split.
Which one should you use?
- XML/View app: ConstraintLayout with a Guideline, or LinearLayout weights for a very simple two-part screen.
- Compose app:
Column/RowwithModifier.weight. - Tablets and foldables: also look at
WindowSizeClassto switch between a top/bottom split on phones and a left/right split on wide screens.




Comments
Post a Comment