Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 104 ยท Building a Real UI

Adaptive Layouts and Window Size Classes

Make your Android UI work on phones, tablets and foldables: WindowSizeClass, list-detail layouts, NavigationSuiteScaffold, insets and edge-to-edge, with runnable stand-ins.

An Android app no longer runs only on a phone held upright. The same APK runs on small phones, large phones, foldables that open into a tablet, tablets, Chromebooks and desktop-style windows, and it can be resized in split-screen or free-form mode at any moment. If you design for one fixed width, the app looks stretched on a tablet and cramped in a narrow window. Adaptive layouts react to the space the app actually has, not to the model of the device.

This lesson explains window size classes, how to choose between a one-pane and a two-pane layout, the navigation components that adapt, and how insets and edge-to-edge drawing fit in. The Compose code is read-only (it needs the Android SDK); the TryIts are stand-ins that make the same decisions in plain Kotlin. If you need a refresher on the building blocks, see Row, Column, Box and Arrangements.

Think in window size, not device type

Do not ask "is this a tablet?". A phone in split-screen can be narrower than a phone alone, and a foldable changes size when it unfolds. Ask instead: how wide and how tall is the window right now? Android groups the answer into three window size classes per dimension: compact, medium and expanded. The usual width breakpoints are:

Width class Width in dp Typical situation
Compact under 600 Phone in portrait, small split-screen window
Medium 600 up to 840 Tablet in portrait, unfolded foldable, large phone in landscape
Expanded 840 and up Tablet in landscape, desktop windows

Heights have their own classes (compact under 480 dp, medium up to 900 dp, expanded beyond), used less often. Width drives most layout decisions. In code, you read it with the Material 3 window size class library:

Kotlin
// read-only example: needs the Android SDK and the material3-window-size-class artifact
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            val windowSizeClass = calculateWindowSizeClass(this)
            AppTheme { App(windowSizeClass.widthSizeClass) }
        }
    }
}

@Composable
fun App(widthClass: WindowWidthSizeClass) {
    when (widthClass) {
        WindowWidthSizeClass.Compact -> OnePaneLayout()
        WindowWidthSizeClass.Medium -> OnePaneWithRail()
        WindowWidthSizeClass.Expanded -> TwoPaneLayout()
    }
}

Newer versions of the library offer currentWindowAdaptiveInfo() in the adaptive library, which returns the same classes. The class is recalculated when the window changes, and your composables recompose with it. There is no restart of the activity needed for a resize if you handle the configuration change, which Compose apps normally do.

The first stand-in classifies widths using the same breakpoints and chooses a layout. Try changing the widths to see where the boundaries are.

Kotlin Choosing a layout from window width (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Notice that the boundaries are inclusive on the upper class: exactly 600 dp is medium and exactly 840 dp is expanded.

List-detail and other canonical layouts

Material guidance defines a few canonical layouts that adapt well:

  • List-detail: a list of items and the selected item's content. On compact windows you show one at a time (tap an item to open the detail); on expanded windows you show both side by side.
  • Supporting pane: a main content area with a secondary pane that supports it, such as a document and a comments panel.
  • Feed: a grid whose column count grows with the width.

Each is a layout where the same data and the same screens are arranged differently. The recommended way to build them is the adaptive library (ListDetailPaneScaffold, SupportingPaneScaffold), which decides how many panes fit and animates between them:

Kotlin
// read-only example: material3-adaptive library
@Composable
fun MailScreen(emails: List<Email>) {
    val navigator = rememberListDetailPaneScaffoldNavigator<Email>()
    ListDetailPaneScaffold(
        directive = navigator.scaffoldDirective,
        value = navigator.scaffoldValue,
        listPane = {
            AnimatedPane {
                EmailList(emails) { navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, it) }
            }
        },
        detailPane = {
            AnimatedPane {
                navigator.currentDestination?.contentKey?.let { EmailDetail(it) }
            }
        },
    )
}

The scaffold shows one pane when the window is narrow and two when it is wide, and the navigator handles Back correctly in both modes. If you build a simple version by hand, the principle is the same: keep a single state (the selected item) and let the window size decide whether the detail is a separate screen or a second pane.

flowchart TD
    W["Window width"] --> C{"Width class?"}
    C -->|Compact| A["List screen<br/>tap opens Detail screen"]
    C -->|Medium| B["List screen with rail<br/>tap opens Detail screen"]
    C -->|Expanded| D["List and Detail side by side<br/>selection is shown at once"]
    A --> S["Same state: selected item"]
    B --> S
    D --> S

One state, three arrangements: only the layout changes with the window size.

The second stand-in implements this decision. It models the selected item as state, and the layout function returns which panes are visible. Resizing from wide to narrow keeps the selection.

Kotlin List-detail panes from a window width (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Adaptive navigation

Navigation controls also adapt. The Material 3 pattern is a navigation bar at the bottom on compact windows, a navigation rail on the side for medium, and a permanent navigation drawer for expanded. You do not need to switch between them yourself: NavigationSuiteScaffold takes the destinations once and picks the component from the window size:

Kotlin
// read-only example: material3-adaptive-navigation-suite library
@Composable
fun AppShell() {
    var current by rememberSaveable { mutableStateOf(Destination.Home) }
    NavigationSuiteScaffold(
        navigationSuiteItems = {
            Destination.entries.forEach { dest ->
                item(
                    selected = dest == current,
                    onClick = { current = dest },
                    icon = { Icon(dest.icon, contentDescription = dest.label) },
                    label = { Text(dest.label) },
                )
            }
        },
    ) {
        ScreenFor(current)
    }
}

You will connect these destinations to a real navigation graph in Bottom Navigation and Nested Graphs.

Insets and edge-to-edge

Since Android 15 apps draw edge-to-edge by default when they target SDK 35: your content goes behind the status bar and the navigation bar, and you are responsible for keeping interactive content clear of them. The areas the system occupies are called window insets: the status bar, the navigation bar, the display cutout (notch), the on-screen keyboard (the IME). Call enableEdgeToEdge() in onCreate for consistent behavior on older versions too.

Material components handle most of it for you: a Scaffold applies insets to its bars, and the innerPadding it passes includes them. For custom layouts, use modifiers such as Modifier.safeDrawingPadding(), Modifier.statusBarsPadding(), Modifier.navigationBarsPadding() or Modifier.imePadding() for a text field that must stay above the keyboard. A background (such as an image) can extend behind the bars, while text and buttons should stay inside the safe area. Remember that on a tablet or foldable the window can also have rounded corners and a taskbar, which is another reason to use insets instead of fixed padding.

Common mistakes

  • Checking the device model or orientation instead of window size.
  • Hard-coding widths such as Modifier.width(360.dp) on top-level containers.
  • Keeping different state for each layout. The selected item should be one source of truth, or it is lost when the window resizes.
  • Locking the orientation in the manifest. Large screens ignore it for many apps, and it blocks users who prefer landscape.
  • Applying insets twice (a Scaffold plus your own statusBarsPadding), which leaves a gap.
  • Testing only on a phone emulator. Use the resizable emulator profile or the Android Studio device configurations to test compact, medium and expanded windows.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which width in dp is the first to be classified as Expanded?

    Compact is under 600 dp, medium is 600 up to 840 dp, and expanded starts at 840 dp.
  2. 2. Why should you avoid checking 'is this a tablet' in your code?

    A phone window can be narrower or wider depending on split-screen, free-form mode and folding. The size of the current window is what matters.
  3. 3. What does NavigationSuiteScaffold do?

    You declare the destinations once, and the scaffold displays them as a bottom bar on compact windows, a rail on medium and a drawer on expanded.
  4. 4. In a list-detail layout, where should the selected item live?

    A single source of truth keeps the selection when the window changes; only the arrangement of panes depends on the size.

Summary

  • Design for the size of the window, not the type of device; it can change at runtime.
  • Window size classes: width compact under 600 dp, medium under 840 dp, expanded from 840 dp.
  • Canonical layouts (list-detail, supporting pane, feed) arrange the same state differently; the adaptive library provides scaffolds for them.
  • NavigationSuiteScaffold picks a bar, rail or drawer automatically.
  • Draw edge-to-edge and use insets (Scaffold padding, safeDrawingPadding, imePadding) to keep content clear of system UI.
  • Compose code is read-only here; the TryIts model the decisions in plain Kotlin.

Next: Views Interop and Legacy XML