This project demonstrates how to design and build responsive and adaptive UIs in Jetpack Compose that work consistently across Android phones with varying widths, heights, DPIs, and resolutions.
The goal of this repo is to help Android developers understand how to structure UI layouts so they scale properly across devices without complex logic.
Using dp and sp ensures your UI remains consistent regardless of DPI differences.
The core challenge in UI consistency is adapting layouts to different screen dimensions, not DPI.
This project demonstrates two main methods:
Modifiers in Jetpack Compose allow your UI to adjust automatically based on available space.
Techniques shown in this project:
weight()— distribute space in Rows/ColumnsfillMaxWidth()+fillMaxSize()— proportional sizingfillMaxWidth(fraction)— fractional layoutaspectRatio()— maintain scalematchParentSize()wrapContentSize()
These approaches are lightweight, clean, and recommended for phone-based UIs.
Use this when you need the UI to change based on screen size.
This repo shows:
Example:
val boxWidth = maxWidth * 0.3fWith safe bounds using:
boxWidth.coerceIn(min, max)Example:
when (maxWidth) {
in 360.dp..390.dp -> { /* layout A */ }
in 390.dp..420.dp -> { /* layout B */ }
}Compose may show a yellow lint warning because BoxWithConstraints expects an @UiComposable scope.
The fix used in the project:
with(LocalDensity.current) {
// your composables
}- Jetpack Compose
- Kotlin
- Material 3
- Android Studio (Latest Version)
- Compose UI Modifiers
- BoxWithConstraints
By exploring this repo, you’ll learn:
- How to make UIs scale across different phone sizes
- When to use modifiers vs
BoxWithConstraints - How to apply percentage sizing safely
- How to categorize layouts with screen-width breakpoints
- How to avoid bugs caused by DPI differences
- How to structure Compose UI for responsiveness
If you find this helpful:
- ⭐ Star the repository
- 🔄 Share it
- 🧑💻 Follow for more Android/Compose content