跪拜 Guibai
← All articles
Kotlin · Android

Modern Android Screen Adaptation: Three Layers, Not One Scale Factor

By 阿健君 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Android 16 will break apps that still hard-code portrait or disallow resizing on large screens, and edge-to-edge on Android 15 changes how content is inset. Adopting the three-layer approach and the official adaptive APIs is now the only way to avoid broken layouts across phones, foldables, tablets, and desktop windows.

Summary

Device classes now range from 320dp small-fold outer screens to 1280dp+ tablets and arbitrary desktop windows. A single dp scale factor cannot cover this spread, and the old "design once, layout-land for landscape" workflow breaks down. Modern adaptation is a three-layer system: resource qualifiers handle density, language, and theme substitution; layouts become elastic with constraints, weights, and adaptive grids; WindowSizeClass decides the structural form, such as single, two, or three panes and the navigation shape.

The official breakpoints are 600dp and 840dp: Compact under 600dp, Medium 600 to 839dp, Expanded at or above 840dp. Compose's `currentWindowAdaptiveInfo()` gives these values reactively, and `BoxWithConstraints`, `GridCells.Adaptive(160.dp)`, `ListDetailPaneScaffold`, and `NavigationSuiteScaffold` handle local responsiveness, column count, list-detail navigation, and bottom-bar-versus-rail switching without hand-written breakpoints.

Foldable support adds another dimension: `FoldingFeature` exposes hinge state, orientation, separation, and occlusion, and code must convert hinge bounds from screen to window coordinates before placing panes. State continuity on fold/unfold relies on ViewModel plus SavedStateHandle and rememberSaveable, not on suppressing recreation. Android 15 forces edge-to-edge for targetSdk 35 apps, and Android 16 ignores orientation locks and resize restrictions on large screens for targetSdk 36 apps, so apps must accept any window shape.

Takeaways
— SmallestWidth (sw) qualifiers describe a device's short-side dp; w qualifiers describe the current window width and respond to split-screen and folding changes.
— WindowSizeClass ranges: Compact < 600dp, Medium 600-839dp, Expanded >= 840dp; height classes also exist.
— The old Toutiao density hack rewrites DisplayMetrics.density to a fixed design width; it breaks in multi-window, during foldable inner/outer switching, and conflicts with system font scaling.
— Use WindowMetricsCalculator.computeCurrentWindowMetrics() instead of Display.getMetrics() for current window bounds.
— Foldable hinge bounds are in screen coordinates; subtract the window origin before laying out panes.
— Do not use configChanges to suppress recreation; use ViewModel + SavedStateHandle and rememberSaveable for state continuity.
— Android 15 (API 35) forces edge-to-edge for targetSdk >= 35; handle WindowInsets.safeDrawing.
— Android 16 (API 36) ignores screenOrientation, resizeableActivity=false, and aspect-ratio limits on devices with smallest width >= 600dp.
— BoxWithConstraints and GridCells.Adaptive(160.dp) let column count follow content instead of fixed breakpoints.
— For wide and short devices (e.g., wide foldable unfolded), judge by width and height combined, not orientation alone, and avoid replacing bottom nav with a rail just because width passes 560dp.
— ListDetailPaneScaffold and NavigationSuiteScaffold handle list-detail and navigation shape adaptation automatically.
Conclusions

The density hack works because screen width is fixed on a normal phone; as soon as windows become resizable, any solution that bases density on widthPixels is measuring the wrong thing.

The guide's content-driven stance on breakpoints is a useful antidote to over-engineering; Material's numbers are starting points, and content constraints like readable line length should override them.

Width beats orientation for foldables; an unfolded device can remain portrait while exceeding 600dp, so orientation checks miss the layout change.

Android 16's rule changes are a forced-migration event; apps that relied on portrait locks and non-resizable activities will have to adapt whether they planned it or not.

The three-layer model separates concerns cleanly: resource substitution for pixels, layout elasticity for space, and window class for structure. Trying to solve all three with one mechanism is what made the old approach fail.

Concepts & terms
WindowSizeClass
Android's official classification of window width/height into Compact, Medium, and Expanded, with thresholds at 600dp and 840dp for width, used to drive structural UI decisions.
FoldingFeature
A Jetpack WindowManager API that describes a foldable device's hinge state, orientation, whether it separates content, and occlusion type.
BoxWithConstraints
A Compose composable that exposes maxWidth and maxHeight constraints, enabling local responsive layouts without needing Activity recreation.
GridCells.Adaptive
A LazyVerticalGrid column definition where each column is at least a minimum size and the grid fits as many columns as possible, letting content decide the column count.
SmallestWidth qualifier (sw)
A resource qualifier that matches devices by the dp value of the shorter side of the screen; it is stable across rotation and useful for device-tier selection.
Edge-to-edge
The Android 15+ default where content draws under system bars; apps must apply WindowInsets to avoid content being obscured by the status or navigation bars.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗