Android LinearLayout is a ViewGroup subclass, used to provide child View elements one by one either in a particular direction either horizontally or vertically based on the orientation property. We can specify the linear layout orientation using android:orientation attribute.
All the child elements arranged one by one in multiple rows and multiple columns.
- Horizontal list: One row, multiple columns.
- Vertical list: One column, multiple rows.
In this article, we are going to discuss declaration and implementation of LinearLayout.
How to declare LinearLayout in XML file?
First of all, we should declare the LinearLayout in layout file using the below code.
LinearLayout in activity_main.xml file
Following is the code for LinearLayout in xml file.
When we have created layout, we need to load the XML layout resource from our activity onCreate() callback method and access the UI element form the XML using findViewById.
We can run the application using the Android Virtual Device(AVD) to get the output of the above code.
- Android Toast in Kotlin
- Android TableLayout in Kotlin
- Android FrameLayout in Kotlin
- Kotlin Android Tutorial
- Android Animations in Kotlin
- Android Slide Up/Down in Kotlin
- Android Fade In/Out in Kotlin
- Android WebView in Kotlin
- Android ListView in Kotlin
- Android RelativeLayout in Kotlin
- Kotlin Coroutines on Android
- Android EditText in Kotlin
- How to Add RangeSeekbar in Android Using Kotlin?
- Thread Priority in Kotlin & Android
- Android progress notifications in Kotlin
- Android Rotate animations in Kotlin
- Android Motion Layout in Kotlin
- How to create project in Android Studio using Kotlin
- How to add a custom styled Toast in Android using Kotlin
- Difference between Java and Kotlin in Android with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai