Asked 7 years ago
24 Feb 2017
Views 1467
sachin

sachin posted

relativeLayout vs LinearLayout in android

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

Mitul Dabhi
answered Nov 30 '-1 00:00

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 .

Post Answer