Meta title: Adaptive UI in Android with Jetpack Compose | Kotlin Guide
Meta description: Learn how to build adaptive Android apps for phones, tablets, and foldables using Kotlin, Jetpack Compose, window size classes, adaptive navigation, and list-detail layouts.
Primary keywords: Adaptive UI Android, Jetpack Compose adaptive layout, Kotlin Android development
Related keywords: Android large-screen development, responsive Android UI, window size classes, adaptive navigation, Compose list-detail layout, Android tablet app development
Introduction: Build Android Apps for Every Screen
Android development is no longer limited to smartphone screens. Today's applications run on smartphones, tablets, foldable devices, Chromebooks, and resizable windows.
For developers, this creates an important challenge: how can we design an application that provides a consistent and intuitive experience across different screen sizes?
The answer is adaptive UI design.
With Kotlin and Jetpack Compose, Android developers can build interfaces that respond to the space available to an application. Instead of simply stretching a mobile layout across a tablet screen, developers can reorganize content, change navigation patterns, and display multiple sections simultaneously.
In this guide, we explore the concepts demonstrated in Google's official Android Developers codelab, Build an app with an adaptive layout. Using the Reply email application as an example, we will look at window size classes, compose previews, list-detail layouts, navigation, and testing.
Official tutorial: Build an app with an adaptive layout—Android Developers
1. What Is Adaptive UI in Android?
Adaptive UI is an approach to designing interfaces that respond to the available application window size and device configuration.
Consider an email application.
On a smartphone, displaying an email list and the complete contents of an email side by side may make both sections difficult to use. A better approach is to show the list first and open the selected email separately.
On a tablet, there is usually enough horizontal space to display the email list on the left and the selected message on the right.
Both layouts provide access to the same functionality, but each is optimized for its available space.
Adaptive design can change:
The arrangement of UI components.
The navigation component used by the application.
The number of content panes displayed simultaneously.
The amount of information visible at once.
The spacing and presentation of content.
The goal is not to create a separate application for every device. It is to build a flexible application that adjusts its presentation intelligently.
2. Why Use Jetpack Compose for Adaptive Layouts?
Jetpack Compose is Android's modern declarative UI toolkit. It allows developers to describe an interface using Kotlin functions annotated with @Composable.
Instead of manually updating individual views whenever the layout changes, developers describe the UI based on the current application state and available space.
Compose offers several advantages for adaptive development:
Reusable components: The same composable can be reused in different layouts.
State-driven interfaces: UI content can respond to changes in selection, navigation, and application state.
Flexible layouts: Components such as Row, Column, and adaptive layout scaffolds help organize content.
Preview support: Developers can inspect different screen configurations directly inside Android Studio.
Material 3 integration: Adaptive navigation and layout components help implement interfaces suited to different window sizes.
These features make Jetpack Compose a practical choice for building maintainable Android applications that support multiple form factors.
3. Understanding Window Size Classes
One of the fundamental concepts in adaptive Android development is the window size class.
A window size class describes the available application window using categories such as compact, medium, and expanded.
It is important to understand that these classes describe the space available to the application, not necessarily the physical size of the device. A tablet running two applications in split-screen mode, for example, may provide less space than expected.
For width, the commonly used Material window size class breakpoints are:
| Width category | Available width |
|---|---|
| Compact | Below 600 dp |
| Medium | 600 dp to below 840 dp |
| Expanded | 840 dp to below 1200 dp |
| Large | 1200 dp and above |
The exact layout behavior should be selected according to the application's requirements and the adaptive API being used.
For example, a compact window might display a bottom navigation bar, while a medium window might use a navigation rail. An expanded window could use a permanent navigation drawer or display additional content panes.
The important principle is to base layout decisions on available space rather than hardcoding behavior for specific phone or tablet models.
4. Create Adaptive Previews in Android Studio
Android Studio's Compose preview functionality makes it easier to inspect how an interface behaves at different widths.
Instead of repeatedly running the application on multiple emulators, developers can create previews for compact, medium, and expanded layouts.
For example:
@Preview(showBackground = true, widthDp = 400)
@Composable
fun CompactPreview() {
ReplyTheme {
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Compact
)
}
}
}
@Preview(showBackground = true, widthDp = 700)
@Composable
fun MediumPreview() {
ReplyTheme {
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Medium
)
}
}
}
@Preview(showBackground = true, widthDp = 1000)
@Composable
fun ExpandedPreview() {
ReplyTheme {
Surface {
ReplyApp(
windowSize = WindowWidthSizeClass.Expanded
)
}
}
}Note: This example illustrates the preview concept and assumes your ReplyApp accepts a WindowWidthSizeClass parameter. Adapt it to your project's actual APIs and dependencies.
These previews make it easier to identify problems such as excessive whitespace, cramped content, or navigation elements that do not fit the available window.
They also act as useful documentation for other developers reviewing the project.
5. Implement a List-Detail Layout
One of the most useful patterns for large-screen applications is the list-detail layout.
It is especially suitable for:
Email clients.
Messaging applications.
Product catalogues.
Contact management systems.
News applications.
Document browsers.
The layout contains two primary sections: a list of items and the details of the selected item.
On compact screens, the application can show one section at a time. On larger screens, both sections can appear side by side.
The Android adaptive layout codelab demonstrates this approach using the Reply email application.
Using ListDetailPaneScaffold
Jetpack Compose Material 3 Adaptive provides ListDetailPaneScaffold for implementing this type of layout.
A simplified illustration is shown below:
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun EmailContent(
emails: List<Email>,
selectedEmail: Email?
) {
ListDetailPaneScaffold(
listPane = {
EmailList(
emails = emails
)
},
detailPane = {
selectedEmail?.let { email ->
EmailDetails(
email = email
)
}
}
)
}This snippet illustrates the two-pane structure; the complete implementation must also supply the appropriate scaffold directive and value, navigation state, and other parameters required by the version of the adaptive API used in your project.
The list pane displays available emails, while the detail pane displays the currently selected message.
The adaptive scaffold can determine how the panes are presented according to the available space and its configuration.
This is more maintainable than building completely separate email interfaces for phones and tablets.
6. Adapt Navigation to Different Screen Sizes
Navigation is another important aspect of adaptive design.
A bottom navigation bar can work well on a compact smartphone because the available horizontal space is limited. On a larger device, a navigation rail or permanent drawer can make better use of the available area.
Material 3 provides adaptive navigation components that can help developers choose an appropriate navigation presentation.
The Reply application demonstrates how navigation and content layouts can change as the window size changes.
For example:
Compact windows can use bottom navigation.
Medium windows can use a navigation rail.
Expanded windows can use a permanent drawer when appropriate.
These are design examples, not rules that every application must follow.
Your choice should depend on the number of destinations, the application's information architecture, and how users interact with the content.
Handle back navigation
Navigation should also behave correctly when the application switches between compact and expanded layouts.
On a phone, opening an email may navigate from the list to a separate detail screen. The Back button should return the user to the list.
On a tablet, both panes may already be visible. In this case, selecting an email can simply update the detail pane.
The application should preserve the selected item and provide sensible navigation behavior as the window changes.
7. Manage State Separately from UI Presentation
Adaptive applications benefit from separating application state from the way content is displayed.
For example, an email application may maintain:
The current list of emails.
The selected email.
The active mailbox.
The current navigation destination.
The same state can be presented in different layouts depending on the available window size.
A ViewModel can manage application-related state, while composables render that state.
This separation helps reduce duplicated business logic and makes the interface easier to test.
It is particularly useful when supporting foldable devices, where a user may change the window size without intending to change the selected email or lose their place in the application.
8. Test Adaptive Layouts Across Devices
An adaptive interface should be tested at different widths, orientations, and window configurations.
Compose previews are a useful first step, but they are not a substitute for running the application.
Android Studio's resizable emulator can help you test phones, tablets, and other supported configurations.
During testing, verify that:
Content remains readable at compact widths.
Navigation components change appropriately.
The selected item remains consistent when resizing.
The list and detail panes display the correct content.
Back navigation works as expected.
The layout handles orientation changes.
Empty states and loading states remain usable.
Accessibility and touch targets remain appropriate.
You can also create automated UI tests that verify which components appear for a particular configuration.
Testing should focus on actual behavior, not simply whether the application builds successfully.
9. Common Mistakes to Avoid
Stretching a mobile interface across a tablet
Increasing the width of every component does not necessarily improve usability. Large screens often benefit from additional columns, side-by-side panes, and more deliberate content spacing.
Hardcoding device models
Avoid designing a layout exclusively for a specific phone or tablet. Base decisions on available window space and the requirements of the UI.
Duplicating entire screens
Creating completely separate implementations for every device category can lead to duplicated code and inconsistent behavior. Prefer reusable composables where the same functionality can serve multiple layouts.
Ignoring resizing and fold states
A foldable device may change its available window space while the application is running. Test how the UI responds to these changes.
Testing only with previews
Previews help you inspect layouts quickly, but real emulator testing is still necessary for navigation, state changes, resizing, and interaction behavior.
10. Practical Applications of Adaptive UI
Adaptive design is useful far beyond an email client.
Banking and fintech apps: Display account summaries beside transaction details on larger screens.
E-commerce applications: Show product listings alongside product details, filters, or comparison information.
Business management apps: Present dashboards, reports, and supporting information in a multi-pane layout.
Education apps: Display learning material alongside notes, navigation, or exercises.
Productivity apps: Keep navigation visible while users work with documents, tasks, calendars, or project information.
For Android developers, adaptive design can therefore become an important part of building professional applications for business and consumer use.
Conclusion
Building adaptive Android applications requires more than making a mobile layout fit a larger display.
It requires understanding the available window space, selecting appropriate navigation patterns, organizing content effectively, managing state correctly, and testing the experience across supported configurations.
Kotlin and Jetpack Compose provide flexible tools for implementing these ideas. With window size classes, reusable composables, adaptive navigation, list-detail layouts, and Android Studio previews, developers can create applications that feel natural on both compact and expanded screens.
The best place to begin is Google's official adaptive layout codelab. Work through the Reply application example, experiment with different window sizes, and apply the same principles to your own projects.
Continue learning: Open the official Android Developers codelab.
Build once, adapt intelligently, and deliver a better experience across Android devices.
Suggested tags
Android Development, Kotlin, Jetpack Compose, Android Studio, Adaptive UI, Mobile App Development, Large Screen Development
Suggested social media post
Building Android apps for phones alone is no longer enough.
With Kotlin and Jetpack Compose, developers can create adaptive interfaces that make better use of tablets, foldables, and resizable application windows.
In this guide, we explore window size classes, adaptive navigation, list-detail layouts, reusable composables, and testing strategies based on Google's official Android Developers codelab.
Read the guide and start building better adaptive Android experiences.
#AndroidDevelopment #Kotlin #JetpackCompose #AndroidStudio #MobileAppDevelopment #AdaptiveUI

Comments
Post a Comment