Reputation: 145
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>
Upvotes: 9
Views: 59292
Reputation: 6181
In Latest versions of android studio i believe this will be the way to do it.
Go to res-> layout folder and Right Click on it and you get a sidebar asking for what type of file you want to create
Go to -> Edit File Templates option.
You will see this dialog opened. You see both options right there inside Other tab These options are LayoutResourceFile.xml and LayoutResourceFile_vertical.xml
Change the ${ROOT_TAG} to LinearLayout in both of these LayoutResourceFile.xml and LayoutResourceFile_vertical.xml and you will always get LinearLayout as parent for future.
Upvotes: 2
Reputation: 93
If you are using Eclipse, just: Rigth click, change layout and select the layout of your choice.
Upvotes: 7
Reputation: 6614
To change the Parent
of your layout XML
file follow these steps:
layout
folder in res
folder from project folder
in eclipse. (<project-folder/res/layout>
)New -> Other...
. Refer picture: Android Layout XML file
option from here. Next
and select LinearLayout
as Root Element
and give File Name
. Press FinishLayout XML
has the root element as LinearLayout
Upvotes: 7
Reputation: 4383
Replace the following tags :
<RelativeLayout
... >
</RelativeLayout>
by those :
<LinearLayout
... >
</LinearLayout>
In addition, you should remove the following from your TextView attributes :
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
because they apply for the relative layout and not the linear layout.
Upvotes: 19
Reputation: 2534
When you create new XML file at that time you can assign layout to it.But when you create new project at that time you can not change layout you have to change it after creation of project.So go to .xml tab in XML file there you can edit layout. Hope this helps.
Upvotes: 0
Reputation: 27549
You just need to change this tag <RelativeLayout ...>
with <LinearLayout ...>
, and don't forget to close it with same Layout
Upvotes: 4