🚀 Jetpack Compose Layouts
Tags: jetpackcompose, android, design, kotlin
Published: 2020-10-24 06:53:12

Howdy Android Devs👋, This is my first article for Android 🥰.  In this article, we gonna see the basics of Layout in Jetpack compose 📒 & How to use them 💡.

&nbsp;

Before jumping 🏃🏻‍♂️ into the topic let's learn about Jetpack compose first!

&nbsp;

# **What is Jetpack Compose 🤔?**

* Jetpack Compose is Android’s modern toolkit for building native UI. 

* It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.

&nbsp;

## **Some Interesting facts below 👇**

![Screenshot 1942-08-02 at 10.43.17](https://dev-to-uploads.s3.amazonaws.com/i/froctgxg4kaxumlvihvr.png)

&nbsp;
 
## **Now let's learn about layouts in compose 😋**

Jetpack compose have various layouts in this article we gonna the see about standard layouts 👇

1. Column
2. Row
3. Box
4. Constraint etc...

&nbsp;

Now let's see how to use the above standard layout in compose 👍

&nbsp;

## **What is the Column Layout?**
Use Column to place items vertically on the screen. It's like a `LinearLayout (Vertical Orientation)` in Android XML.

&nbsp;

## **Example for Column Layout💡**

```
@Composable
fun ProfileCard() {
  Column {
    Text("Spikey Sanju")
    Text("Android Developer & UI/UX Designer")
  }
}
```
&nbsp;

In this above example, We have added the `@Composable` annotation to create the Composable function.

1. Composable functions can be only called from another Composable function.

2. Composable functions are the functions that we use to draw the UI on the screen. All the widgets written inside it is rendered on the screen.

&nbsp;

### **Now let's take a look inside the sample code 🕵🏻‍♂️**

We are placing two text components inside the `Column` layout. Now the `Column` layout will place all the items inside the Column Vertically

&nbsp;

### **Now let's see the output 🥳**

![ROWS & COLUMNS](https://dev-to-uploads.s3.amazonaws.com/i/afa6uix4rh1pqw51r862.png)

Okay, this is how the Column works 😄. Now let's take a look at the `Row` Layout 👍

&nbsp;

## **What is the Row Layout?**
Use Row to place items horizontally on the screen. It's like a `LinearLayout (Horizontal Orientation)` in Android XML.

&nbsp;

## **Example for Row Layout💡**

```
@Composable
fun ProfileCard() {
  Row{

// getting the image from the drawable
            Image(modifier = modifier.preferredSize(60.dp).clip(CircleShape).align(Alignment.CenterVertically),
                    asset = imageResource(id = R.drawable.spikeysanju),
                    contentScale = ContentScale.Crop)


// used to give horizontal spacing between components
            Spacer(modifier = modifier.width(16.dp))

            Column(modifier = modifier.align(Alignment.CenterVertically)) {
                Text(text = "Spikey Sanju", color = Color.Black, style = typography.h6)

// used to give vertical spacing between components
                Spacer(modifier = modifier.height(8.dp))
                Text(text = "Android Developer & UI/UX Designer", color = Color.DarkGray, style = typography.caption)
            }
        }

}
```

&nbsp;

In the above code, we have used Modifiers. Let's explore the modifiers 👨🏻‍💻

&nbsp;

## **What are Modifiers in Compose 😋**

Modifiers allow you to tweak how a composable is presented. Modifiers let you do these sorts of things:

&nbsp;

1. Change the composable's behavior and appearance
2. Add information, like accessibility labels
3. Process user input
4. Add high-level interactions, like making an element clickable, scrollable, draggable, or zoomable

&nbsp;

>Modifiers are standard Kotlin objects. Create a modifier by calling one of the Modifier class functions. You can chain these functions together to compose them:

&nbsp;

### **Now let's see the output for Row Layout 🥳**

![ROWS & COLUMNS](https://dev-to-uploads.s3.amazonaws.com/i/hs7f8hfg2k1u7zuh6gim.png)

&nbsp;

Let's see the blueprint of the above examples for Rows & Columns ℹ️

&nbsp;

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/36qvkdvbdd88yj1wtrx8.png)

&nbsp;

Now you can understand how the layout is combined & arranged. 
This is how you have to combine Rows & Columns to create various layout according to your needs.

&nbsp;

In the next article, we will see how to use Box Layout, Constraint Layout & much more fun kinds of stuff in jetpack compose ... Stay tuned 🥳🤘...


Comment down your thoughts below 👇