Asked 30+ days ago
24 Feb 2017
Views 261
sachin

sachin posted

relativeLayout vs LinearLayout in android

what is difference between relativeLayout vs LinearLayout in android ?
Mitul Dabhi

Mitul Dabhi
answered Jan 21 '18 20:17

Linear Layout arrange all element in single direction horizontally or vertically .


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
>
</LinearLayout>

android:orientation will decide it should layout in direction of horizontal or vertical
android:orientation="horizontal" or android:orientation="vertical"

In Relative Layout each element position is defined by relative to its sibling or parents .


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</RelativeLayout >

we do not have orientation property for Relative Layout.
we can set element relative to each other so change in one reflect to other .

Edit Answer
Share
Post Answer