Do you have any idea on how to use the new Constraint Layout that was recently announced at this year's Google I/O?
Consider using flatter layouts such as RelativeLayout or GridLayout to improve performance.
A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread).
And it can go worse if Nested Relative Layout is used, the already twice measured child of inner Relative Layout would be again measured twice by outer Relative Layout which becomes 4 times just for one view! So Linear Layout should preferred over Relative Layout!
If you have the choice start with ConstraintLayout, but if you already have your app in RelativeLayout, stay with it. That's all I have been following. RelativeLayout is very limited in functionality and many complex layouts can't be made using it, especially when ratios are involved.
You can go to an existing layout resource file, open the visual editor and right-click on a RelativeLayout (for example) and click the option to convert to a constraint layout.
You also have to add the Gradle dependency in build.gradle file:
compile 'com.android.support.constraint:constraint-layout:1.0.0'
From Docs
If you're updating an existing project, proceed as follows:
Ensure you have the latest Android Support Repository (version 32 or higher): // This was the part that was missing for me
Click Tools > Android > SDK Manager. Click the SDK Tools tab. Select Android Support Repository, then click OK.
Add the updated Constraint Layout library as a dependency in your build.gradle file:
dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.0' }
In the toolbar or sync notification, click Sync Project with Gradle Files.
To add a new constraint layout to your project:
To convert an existing layout to a constraint layout:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With