Saturday, 15 April 2017

              Android ConstraintLayout
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.
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
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

Android ConstraintLayout is used to define a layout by assigning constraints for every child view/widget relative to other views present.
A ConstraintLayout is similar to a RelativeLayout, but with more power. The aim of ConstraintLayout is to improve the performance of the applications by removing the nested views with a flat and flexible design.
A view inside the ConstraintLayout has handles(or anchor points) on each side which are used to assign the constraints. Let’s drag and drop a TextView on the layout and assign the constraints to it.


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



.