To use android ConstraintLayout, make sure you’re using the latest Android Studio version. Ideally, Android Studio 2.2 and above. We need to download the necessary SDK Tools for ConstraintLayout from the SDK Manager.
Create a new empty activity project and add the following dependency inside the build.gradle file.
To convert an old layout into a ConstraintLayout. Open the design pane of the respective layout, right click the root component and choose the relevant option as Convert RelativeLayout to ConstraintLayout
Android Constraint Layout Overview
The TextView above has three types of handles:
Resize handle – It’s present on the four corners and is used to resize the view, but keeping its constraints intact.
Side handle – It’s the circular handle present on the centre of each side. It’s used to set the top, left, bottom and right constraints of the view.
Baseline handle – It’s used to align the baseline with another textview in the layout.
Notice the Properties inspector pane at the right-hand side:
· Wrap Content – This wraps the view to fill it’s content.
· Any Size – This is similar to match parent
· Fixed Size – This allows us to set constant width and height