Learn Basic Layouts in Android Compose application

https://developer.android.com/develop/ui/compose/layouts/basics

Often these building blocks are all you need

You can write your own composable function to combine these layouts into a more elaborate layout that suits your app

image

Android Compose handles nested layouts efficiently, making them a great way to design a complicated UI

This is an improvement from Android Views, where you need to avoid nested layouts for performance reasons.

1. My first layout sample: Adding a Column with two Text components

image

@Composable
fun ArtistCardColumn() {
    Column {
        Text("Alfred Sisley")
        Text("3 minutes ago")
    }
}

2. Using Row, Column and Text components

Use Row to place items horizontally on the screen. Both Column and Row support configuring the alignment of the elements they contain

image

@Composable
fun ArtistCardRow(artist: Artist) {
    Row(verticalAlignment = Alignment.CenterVertically) {
        Image(bitmap = artist.image, contentDescription = "Artist image")
        Column {
            Text(artist.name)
            Text(artist.lastSeenOnline)
        }
    }
}

3. Using a Box

Use Box to put elements on top of another. Box also supports configuring specific alignment of the elements it contains.

image

@Composable
fun ArtistAvatar(artist: Artist) {
    Box {
        Image(bitmap = artist.image, contentDescription = "Artist image")
        Icon(Icons.Filled.Check, contentDescription = "Check mark")
    }
}

4. We can use Alignment

image

@Composable
fun ArtistCardArrangement(artist: Artist) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.End
    ) {
        Image(bitmap = artist.image, contentDescription = "Artist image")
        Column { /*...*/ }
    }
}

5.

6.

7.