Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 646
Suhaib Avatar asked Feb 15 '17 23:02

Suhaib


People also ask

Can we use RelativeLayout inside ConstraintLayout?

You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.

Which is better RelativeLayout or ConstraintLayout?

ConstraintLayout has flat view hierarchy unlike other layouts, so does a better performance than relative layout. Yes, this is the biggest advantage of Constraint Layout, the only single layout can handle your UI.

Which is better LinearLayout or RelativeLayout?

Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.

What is the difference between FrameLayout and RelativeLayout in android?

RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...


2 Answers

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

like image 102
Luiz Henrique Carneiro Gonalve Avatar answered Oct 13 '22 02:10

Luiz Henrique Carneiro Gonalve


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'
like image 15
Hargun Singh Avatar answered Oct 13 '22 03:10

Hargun Singh