Skip to content

Shoaibkhalid65/Responsiveness

Repository files navigation

📱 Responsive UI in Android — Jetpack Compose

Ensuring Consistent UI Across All Android Phone Devices

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.


🚀 Key Concepts Covered

✔ Density-independent design

Using dp and sp ensures your UI remains consistent regardless of DPI differences.

✔ Handling screen width & height

The core challenge in UI consistency is adapting layouts to different screen dimensions, not DPI.

✔ Responsive layout techniques

This project demonstrates two main methods:


🧩 1. Responsive UI Using Modifiers (Recommended)

Modifiers in Jetpack Compose allow your UI to adjust automatically based on available space.

Techniques shown in this project:

  • weight() — distribute space in Rows/Columns
  • fillMaxWidth() + fillMaxSize() — proportional sizing
  • fillMaxWidth(fraction) — fractional layout
  • aspectRatio() — maintain scale
  • matchParentSize()
  • wrapContentSize()

These approaches are lightweight, clean, and recommended for phone-based UIs.


🧩 2. Responsive UI Using BoxWithConstraints

Use this when you need the UI to change based on screen size.

This repo shows:

a) Percentage-based sizing

Example:

val boxWidth = maxWidth * 0.3f

With safe bounds using:

boxWidth.coerceIn(min, max)

b) Conditional/UI-breakpoint-based sizing

Example:

when (maxWidth) {
    in 360.dp..390.dp -> { /* layout A */ }
    in 390.dp..420.dp -> { /* layout B */ }
}

Important Tip

Compose may show a yellow lint warning because BoxWithConstraints expects an @UiComposable scope. The fix used in the project:

with(LocalDensity.current) {
    // your composables
}

🛠 Tech Stack

  • Jetpack Compose
  • Kotlin
  • Material 3
  • Android Studio (Latest Version)
  • Compose UI Modifiers
  • BoxWithConstraints

🎯 What You Will Learn

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

⭐ Support

If you find this helpful:

  • ⭐ Star the repository
  • 🔄 Share it
  • 🧑‍💻 Follow for more Android/Compose content

About

A collection of Jetpack Compose practice projects focused on building responsive UIs for different mobile screen sizes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages