[android] How to switch from the default ConstraintLayout to RelativeLayout in Android Studio

I have the latest android Studio (2.3 beta 3) and it seems ConstraintLayout is the default when creating a project. How can I make Android Studio use the RelativeLayout as the default layout element for new projects ?

enter image description here

The answer is


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


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>

Android 3.0

In activity_main.xml

Replace in this tag i.e <android.support.constraint.ConstraintLayout>

android.support.constraint.ConstraintLayout

with

RelativeLayout


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'

Just right click on the ConstrainLayout and select the "convert view" and then "RelativeLayout":


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


A very short way to do it is just right click on the activity_main.xml design background and select convert view then select Relativealayout. Your code in Xml Text will auto. Change. Goodluck


The easiest way would be to select Relativelayout from the Pallete, and then use it.Drag and Drop RelativeLayout over Constraint layout


inefficient solution:

Create a new Layout

  1. Go to /res/layout folder in Android Studio
  2. Right click -> New -> Layout Resource files
  3. give it a name and add .xml at the end
  4. Erase the Root Element field and type 'RelativeLayout'

enter image description here


Try this. It's helped me to change from ConstraintLayout to RelativeLayout.

Try this... That helped me to change from ConstraintLayout to RelativeLayout


The easiest method is to go to your .xml file in text mode, and replace the top line:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

And then proceed to replace it with:

<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

If you then go back into design mode, you can see that you now have a relative layout. This also automatically changes the end tag, so no issues there.


  1. Right click on ConstraintLayout.
  2. Select convertview.
  3. select RelativeLayout

For more clarity refer below image

enter image description here


I think u want to change the default settings of android studio. Whenever a layout or Activity in created u want to create "RelativeLayout" by default. In that case, flow the step below

  1. click any folder u used to create layout or Activity
  2. then "New>> Edit File Templates
  3. then go to "Other" tab
  4. select "LayoutResourceFile.xml" and "LayoutResourceFile_vertical.xml"
  5. change "${ROOT_TAG}" to "RelativeLayout"
  6. click "Ok"

you are done


None of these solutions worked for me...seemingly until I stumbled across this setting, see image. File > Settings > Editor > Layout Editor > Check "Prefer XML Editor"

https://i.stack.imgur.com/9CHe7.png


just do it: in component tree right click on ConstraintLayout and select relativelayout on convert view...


TO CHANGE ConstraintLayout to RelativeLayout: This will work in Android studio 3.0.1

Change->

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"

into

<android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

and->

</android.support.constraint.ConstraintLayout>

nto

</android.widget.RelativeLayout>

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK

Examples related to android-relativelayout

How to switch from the default ConstraintLayout to RelativeLayout in Android Studio Differences between ConstraintLayout and RelativeLayout Moving from one activity to another Activity in Android RelativeLayout center vertical Android Relative Layout Align Center Android: show/hide a view using an animation How to set RelativeLayout layout params in code not in xml? How to create a RelativeLayout programmatically with two buttons one on top of the other? Percentage width in a RelativeLayout What are the differences between LinearLayout, RelativeLayout, and AbsoluteLayout?

Examples related to android-constraintlayout

Constraint Layout Vertical Align Center How to center the elements in ConstraintLayout Android - how to make a scrollable constraintlayout? How to switch from the default ConstraintLayout to RelativeLayout in Android Studio Gradle Sync failed could not find constraint-layout:1.0.0-alpha2 Set width to match constraints in ConstraintLayout Is it possible to put a ConstraintLayout inside a ScrollView? Differences between ConstraintLayout and RelativeLayout How to make ConstraintLayout work with percentage values?