Difference Between LinearLayout and RelativeLayout in Android Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 9 Likes Like Report In Android, LinearLayout and RelativeLayout are view groups used for arranging UI elements , but they are have few differences in their behavior and use cases.Difference Between LinearLayout and RelativeLayoutLinearLayout RelativeLayout We can adjust views and widgets linearly i.e. Horizontally and vertically.We can adjust views and widgets according to one's satisfaction.layout_weight attribute in the linear layout is used to specify the equal or specific size to the particular widget and view by using the following attribute.android:layout_weight = '0' Here Weight is specified as 0 in order to give equal size or space to each view or widget.Various attributes like: layout_toRightOf, layout_toLeftOf, layout_below, layout_alignParentTop, layout_top, layout_alignParentLeft, layout_alignParentRight are used to specify the position of each view and widget.It is useful when we arrange views in a linear fashionIt is useful when we arrange views in a relative fashion.Syntax:<LinearLayout> <!--Views, widgets--></LinearLayout>Syntax:<RelativeLayout> <!--Views, Widgets--></RelativeLayout>Example: In various Apps, LinearLayout is mainly applicable in the SignUp screen where Name, Email, Phone Number, Submit, etc. are arranged in a linear fashion.Example: In Google Play Store, when we open the app, the games, books, movies, and App's sections all are arranges in Relative Layout Fashion. LinearLayout is less used as compared to RelativeLayout.RelativeLayout is used more in applications.We can use LinearLayout inside RelativeLayout.We can also use RelativeLayout as a Child of LinearLayout.LinearLayoutLinearLayout is a type of view group which is responsible for holding views in it either Horizontally or vertically. It is a type of Layout where one can arrange groups either Horizontally or Vertically.Example Diagram: Syntax: XML <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="either vertical or horizontal"> <!--ImageView, TextView, ButtonView etc.--> </LinearLayout> RelativeLayoutRelativeLayout is a layout in which we can arrange views/widgets according to the position of other view/widgets. It is independent of horizontal and vertical view and we can arrange it according to one's satisfaction.Example Diagram: Syntax: XML <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <!--ImageView, TextView, ButtonView etc with specified position--> </RelativeLayout> Program Explaining LinearLayout XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginLeft="35dp" android:layout_marginTop="20sp" android:layout_marginRight="10sp" android:layout_weight="0" android:background="#004d00" android:text=" Geeks" android:textColor="#ffffff" android:textSize="40sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20sp" android:layout_marginRight="10sp" android:layout_weight="0" android:background="#f2f2f2" android:text="For" android:textColor="#004d00" android:textSize="40sp" android:textStyle="bold" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="20sp" android:layout_marginRight="10sp" android:layout_weight="0" android:background="#004d00" android:text="Geeks" android:textColor="@color/white" android:textSize="40sp" android:textStyle="bold" /> </LinearLayout> Layout: Program Explaining RelativeLayout XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white"> <ImageView android:id="@+id/image_gfg" android:layout_width="100dp" android:layout_height="110dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:layout_marginRight="10dp" android:scaleType="fitCenter" android:src="@drawable/gfg" /> <TextView android:id="@+id/gfg_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/image_gfg" android:paddingTop="5dp" android:text="Geeks For Geeks" android:textColor="#004d00" android:textSize="32sp" android:textStyle="bold" /> <TextView android:id="@+id/gfg_location" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/gfg_text" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/image_gfg" android:text="Noida,UttarPradesh" android:textColor="#00b300" android:textSize="25sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/gfg_location" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/image_gfg" android:text="Portal for CS Student" android:textColor="#009900" android:textSize="24sp" /> </RelativeLayout> Output: Create Quiz Comment J jagroopofficial Follow 9 Improve J jagroopofficial Follow 9 Improve Article Tags : Technical Scripter Difference Between Android Technical Scripter 2020 Kotlin Android Java-Android +2 More Explore Android Tutorial 10 min read BasicsIntroduction to Android Development 5 min read History of Android 15+ min read Best Way to Become Android Developer â A Complete Roadmap 7 min read Android Development Prerequisites [2025] - Things to Learn Before Android Development 8 min read Android App Development Fundamentals for Beginners 6 min read Android Architecture 5 min read Android System Architecture 3 min read Android Boot Process 4 min read Difference between Java and Kotlin in Android with Examples 3 min read Interesting Facts About Android 3 min read Software Setup and ConfigurationDownload and Install JDK on Windows, Mac and Linux 6 min read Guide to Install and Setup IntelliJ IDEA for Android App Development 5 min read Guide to Install and Setup Visual Studio for Android App Development 4 min read How to Run the Android App on a Real Device? 2 min read Resolving frequently occurring errors in Android Development 3 min read Android Studio Tutorial 9 min read File Structure & ComponentsComponents of an Android Application 3 min read Introduction to Activities in Android 6 min read Services in Android with Example 10 min read Core TopicsHow Does Android App Work? 7 min read Activity Lifecycle in Android with Demo App 9 min read Introduction to Gradle 4 min read What is Context in Android? 9 min read Bundle in Android with Example 6 min read Activity State Changes In Android with Example 6 min read Processes and Application Lifecycle in Android 7 min read Desugaring in Android 4 min read Difference Between AndroidX and Android Support Libraries 3 min read Memory Leaks in Android 7 min read Layout & ViewLayouts in Android UI Design 3 min read Android UI Layouts 5 min read LinearLayout and its Important Attributes with Examples in Android 3 min read Android LinearLayout in Kotlin 2 min read Android RelativeLayout in Kotlin 4 min read ConstraintLayout in Android 6 min read TextView widget in Android with Examples 5 min read TextView in Kotlin 3 min read Working With the TextView in Android 7 min read Autosizing TextView in Android 6 min read ButtonButton in Android 3 min read How to Add Radio Buttons in an Android Application? 5 min read RadioButton in Kotlin 4 min read How to add Toggle Button in an Android Application 3 min read ToggleButton in Kotlin 2 min read RadioGroup in Kotlin 3 min read Intent and Intent FiltersWhat is Intent in Android? 4 min read Implicit and Explicit Intents in Android with Examples 6 min read How to Send Data From One Activity to Second Activity in Android? 7 min read How to open dialer in Android through Intent? 3 min read Creating Multiple Screen Applications in Android 6 min read How to Open Camera Through Intent and Display Captured Image in Android? 6 min read Toast & RecyclerViewToasts for Android Studio 2 min read What is Toast and How to Use it in Android with Examples? 6 min read Android Toast in Kotlin 3 min read How to Change Toast font in Android? 3 min read How to add a custom styled Toast in Android 4 min read RecyclerView in Android with Example 7 min read Android | Horizontal RecyclerView with Examples 4 min read How to create a nested RecyclerView in Android 5 min read How to Create RecyclerView with Multiple ViewType in Android? 6 min read RecyclerView using ListView in Android With Example 5 min read Like