George Lim George Lim - 5 months ago 14
Android Question

Change Android layout from Relative to Linear

I just started creating android apps, but i have a problem changing the

layout
, every time when i create new android project , it gives me
RelativeLayout
instead of
LinearLayout
, (well, basically i am following the book instruction, but it doesn't teach me how to change it) I assume there must be a default setting so that i can change the
Relativelayout
to
LinearLayout
.

<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" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />

</RelativeLayout>

Answer

To change the Parent of your layout XML file follow these steps:

  • Right click your layout folder in res folder from project folder in eclipse. (<project-folder/res/layout>)
  • Choose option New -> Other.... Refer picture: select layout folder
  • Choose Android Layout XML file option from here. enter image description here
  • Press Next and select LinearLayout as Root Element and give File Name. Press Finishenter image description here
  • Now your Layout XML has the root element as LinearLayout