Row Layout Guide in KMP Compose Multiplatform

Today’s tutorial teaches how to use the Row layout widget in Kotlin Compose Multiplatform. This guide will covert its properties with easy code examples to create cross-platform applications.

Row Layout Guide in KMP Compose Multiplatform

Row Layout Guide in KMP Compose Multiplatform

The Row widget in compose multiplatform is a layout widget to align its child elements horizontally. The purpose of the Row widget is to create beautiful and responsive UI elements in a horizontal line. There are 3 main properties in the Row widget in KMP.

  1. modifier
  2. horizontalArrangement
  3. verticalAlignment

1. Modifiers:

Modifiers are used to set a layout width, and height, and decide whether a layout should be fill width height or width. In easy language, modifiers are used to manage layout boundaries.

2. horizontalArrangement:

It is used to control the horizontal arrangement of children in the row widget. Below mentioned are its properties.

1. horizontalArrangement Arrangement.Start: Start the child elements from the start of the screen from the left to the right side.

Row Layout Guide in KMP Compose Multiplatform

Code:

2. horizontalArrangement Arrangement.Center: Arrange Row child elements horizontally center of the layout screen.

horizontalArrangement Arrangement.Center

Code:

3. horizontalArrangement Arrangement.End: To push all the elements at the end of the layout in horizontal format.

Row Layout Guide in KMP Compose Multiplatform

Code:

4. horizontalArrangement = Arrangement.SpaceAround: To set equal space from both the left and right sides to the child element.

horizontalArrangement = Arrangement.SpaceAround

Code:

5. horizontalArrangement Arrangement.SpaceBetween: Set space between all the elements and push them to the start and end of the screen.

Row Layout Guide in KMP Compose Multiplatform

Code:

6. horizontalArrangement = Arrangement.SpaceEvenly: Set equal space between each element of the row widget.

horizontalArrangement = Arrangement.SpaceEvenly

Code:

3. verticalAlignment:

The vertical alignment sets the vertical arrangement of the Row widget children

1. verticalAlignment = Alignment.Top: To set row widget child elements vertical alignment to Top.

verticalAlignment = Alignment.Top

Code:

2. verticalAlignment = Alignment.CenterVertically: To set Row widget children vertically center alignment.

verticalAlignment = Alignment.CenterVertically

Code:

2. verticalAlignment = Alignment.Bottom: To set Row children’s vertical alignment bottom of the layout.

verticalAlignment = Alignment.Bottom

Code:

Conclusion:

I have tried my best to explain each property of the Row widget in KMP compose multiplatform. If you practice all of them then you surely master Row layout in KMP. Happy coding.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *