How to switch from the default ConstraintLayout to RelativeLayout in Android Studio
Well, I saw the answer above and it worked for me too. But, I gave it a shot, and succeded converting my current project to Relative Layout. Do as follows:
At activity_main.xml tab, change it to text. At the top of it, you'll find the following:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
Just change all before xmlns to RelativeLayout. Doing so will also change the very bottom line where you would find:
</android.support.constraint.ConstraintLayout>
to
</RelativeLayout>
Problem solved! Be happy :P
I am answering this for android studio 2.3.1. One of the easiest ways to set RelativeLayout as default layout is going to text mode and editing the XML file as follows:
Change this line:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
To
<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
And do check your ending tag changes to this:
</android.widget.RelativeLayout>
Also (optionally) go ahead and delete this line if it's being shown in grey:
xmlns:app="http://schemas.android.com/apk/res-auto"
Edit:
This is an optional change to make in project, I came across this tip while going through Udacity's Android Developer Course
If the constraint layout is not needed in the project remove the following dependency from build.gradle by deleting this line and then doing gradle sync:
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
Android studio 3.0
step0:
Close android studio
step1:
Goto C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout\
step2:
Backup simple.xml.ftl
step3:
Change simple.xml.ftl to code below and save :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="12dp"
android:layout_marginTop="21dp"
android:text="don't forget to click useful if this helps. this is my first post at stackoverflow!"
android:textSize="20sp"
/>
</RelativeLayout>
for android studio 3.1
If you want your default android studio change, just follow bellow steps:
first
go to C:\Program Files\Android\Android Studio\plugins\android\lib\templates\activities\common\root\res\layout
i.e. the file directory where you have installed android studio.
then
copy simple.xml from another place just for backup
after that
open simple.xml file and replace it's code as bellow
<?xml version="1.0" encoding="utf-8"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}">
</RelativeLayout>
but if you just want to change this project layout, just go to activity_main.xml and then go to text and post upper code to there