PreviewDevices

@Preview(name = "phone", device = "spec:width=360dp,height=640dp,dpi=480")
@Preview(name = "landscape", device = "spec:width=640dp,height=360dp,dpi=480")
@Preview(name = "foldable", device = "spec:width=673dp,height=841dp,dpi=480")
@Preview(name = "tablet", device = "spec:width=1280dp,height=800dp,dpi=480")
annotation class PreviewDevices

Multi-preview annotation for testing Composables across various device sizes.

Applying this annotation to a Composable function automatically generates preview variants for phone, landscape, foldable, and tablet screen sizes. This ensures your UI is responsive and adapts correctly to different form factors.

Device Specifications

  • Phone: 360×640dp @ 480dpi (standard portrait phone)

  • Landscape: 640×360dp @ 480dpi (phone in landscape orientation)

  • Foldable: 673×841dp @ 480dpi (unfolded device like Galaxy Fold)

  • Tablet: 1280×800dp @ 480dpi (10-inch tablet)

Usage

@PreviewDevices
@Composable
fun MyScreenPreview() {
JetpackTheme {
MyScreen(
screenData = MyScreenData(/* preview data */),
onAction = {}
)
}
}

Combining with Other Preview Annotations

@PreviewDevices
@PreviewThemes // Also test light and dark themes
@Composable
fun MyComponentPreview() {
JetpackTheme {
MyComponent()
}
}

See also