A.G.
A.G.

Reputation: 31

How to set constraints in android studio

I've searched online and I saw that in Android Studio is possible to set the Constraint Layout with the blue prints, but I can't find them. Is there another way to do it?

Upvotes: 3

Views: 23195

Answers (2)

skydroid
skydroid

Reputation: 733

Yes you can.

1.Ensure you have the Android Studio 2.2 Preview & latest Android Support Repository (version 32 or higher):

Click Tools > Android > SDK Manager.

Click the SDK Tools tab.

Select Android Support Repository, then click OK.

Support Repo

2.You have to add following in your compile dependency in build.gradle

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'

then you also have to update your gradle plugin also (Main Project's build.gradle)

classpath 'com.android.tools.build:gradle:2.2.0-alpha2'

Or you can use the latest:

classpath 'com.android.tools.build:gradle:2.2.0-alpha3'

3.In the toolbar or sync notification, click Sync Project with Gradle Files.

4.To add a new constraint layout to your project: Right-click on your module's layout directory, then click New > XML > Layout XML. Enter a name for the layout and enter android.support.constraint.ConstraintLayout for the Root Tag.

OR

To convert an existing layout to a constraint layout:

Open your existing layout in Android Studio 
and select the Design tab at the bottom of the editor window.
In the Component Tree window, 
right-click the layout and click Convert <layout> 
to ConstraintLayout.

Source

Constraint Layout

Upvotes: 3

Vivek Mishra
Vivek Mishra

Reputation: 5705

Easiest way is to first create a Relative Layout properly and then convert it to Constraint Layout.

To convert an existing layout to a constraint layout:

Open your existing layout in Android Studio and select the Design tab at the bottom of the editor window.

In the Component Tree window, right-click the layout and click Convert to ConstraintLayout.

Upvotes: 2

Related Questions