![]() |
In Jetpack Compose, a Spacer is a blank element that is used to create a Space between two UI elements. Suppose, we have created Element 1 and we want to place Element 2 below Element 1 but with a top margin, we can declare a Spacer between the two elements. So in this article, we will show you how you could implement a Spacer in Android using Jetpack Compose. Follow the below steps once the IDE is ready. Step by Step ImplementationStep 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Step 2: Working with the MainActivity.kt file Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail. Kotlin
Output: You can see that Button 1 and Button 2 are separated by 20dp and Button 2 and Text are separated by 200dp. |
Reffered: https://www.geeksforgeeks.org
Android |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |