Difference Between LinearLayout and RelativeLayout in Android Last Updated : 06 Feb, 2025 Comments Improve Suggest changes Like Article 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: Comment More infoAdvertise with us Next Article Difference Between LinearLayout and RelativeLayout in Android J jagroopofficial Follow Improve Article Tags : Technical Scripter Difference Between Android Technical Scripter 2020 Kotlin Android Java-Android +2 More Similar Reads Difference Between View and ViewGroup in Android In Android Layout is used to describe the user interface for an app or activity, and it stores the UI elements that will be visible to the user. An android app's user interface is made up of a series of View and ViewGroup elements. In most cases, android apps will have one or more operations, each o 5 min read What is the Difference Between GRAVITY and LAYOUT_GRAVITY in Android? Aligning the views while designing an application is a quite tedious task. Isn't it? Here comes layout attributes to the rescue! Each layout has a set of attributes that define the visual properties of that layout. There are few common attributes among all the layouts and there are other attributes 3 min read Android - Difference Between RecyclerView and ListView In Android View is a basic building block of UI (User Interface). A view is a small rectangular box that responds to user inputs. RecyclerView and ListView are the two major Views in Android. So in this article, we are going to see the major differences between these two views. RecyclerView Recycler 3 min read Difference Between Modal and Persistent Bottom Sheet in Android Android BottomSheet is a kind of view that is used as supplementary surfaces in mobile apps. This component is a part of the android design support library and is used to expose more data or information, menus, deep linked content, and in place of dialogs. It appears on the screen by sliding up from 3 min read Difference Between AndroidX and Android Support Libraries Support library packages in Android are a set of code libraries whose prime purpose is to provide backward-compatibility to the code and Android API framework. In the real world, there is a strong possibility that an application that is developed on the latest Android version is used on an older ver 3 min read Like