From the course: Android Compose with Kotlin

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Units of measurement with Compose

Units of measurement with Compose - Kotlin Tutorial

From the course: Android Compose with Kotlin

Units of measurement with Compose

- [Instructor] To support a variety of device screen sizes, it's recommended that you use density-independent pixels or dps. In Compose, you'll mostly see dps used with modifiers, to specify the size, padding, margins, and more, of composables. In this example, we have the Icon composable. It's used to display an icon on the screen. We've set its size to 100 dps. See how it appears consistent on both devices, although they differ in pixels per inch? However, when working with text, you should use sps or scalable pixels. It works much the same as dps, but it resizes based on the user's preferred text size. Let's hop over to Android Studio to see a few examples. Here, we have a composable function that contains just a text, and we've defined two preview functions below. The first uses a Nexus 5 device, and the second uses a Pixel 4 XL. I just want to call out that this is another one of the great features of Android Studio when working with Compose, you can preview your designs on…

Contents