Tag: android

ConstraintLayout – Guidelines, Barriers, Chains and Groups

ConstraintLayout – Guidelines, Barriers, Chains and Groups

Since my initial blog post about ConstraintLayout, there have been a whole bunch of new features added (and lots of improvements) to ConstraintLayout. This blog post aims to cover some of the new features, namely Guidelines, Barriers, Chains and Groups.

Some of these features require using Android Studio 3.0 Beta 5 and the beta version of ConstraintLayout. In order to use the beta version of ConstraintLayout, make sure you have at least the following dependency in your app level build.gradle file:

    implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'


Guidelines are small visual helpers to design layouts with. Views can be aligned to a guideline which can simplify layouts, especially if you have the same margin values duplicated on a lot of elements.

Guidelines can be specified in dp from start or end of the screen or they can be a percentage of the width of the screen. To cycle through the different guideline modes, you can click the round icon at the top of the guideline.

To create a guideline and use it, see below:

Guidelines in ConstraintLayout
Guidelines in ConstraintLayout

If you are curious as to how a guideline looks in XML, this is what it looks like:

        app:layout_constraintGuide_begin="20dp" />

Other views in the layout can then constrain themselves to the guideline.


Barriers are one of my favourite features in ConstraintLayout. A barrier is an invisible view that contains reference to the views that you wish to use to form a “barrier” against. If one of the views grows, the barrier will adjust its size to the largest height or width of the referenced items. Barriers can be vertical or horizontal and can be created to the top, bottom, left or right of the referenced views. Other views can then constrain themselves to the barrier.

Below is an example of creating a barrier from two views and constraining a view to it. As you can see, adjusting the size of the TextView, the barrier adjusts its size and the constrained view moves.

Barriers in ConstraintLayout
Barriers in ConstraintLayout

If you are curious as to how this is created, this is what it looks like in XML:

        app:constraint_referenced_ids="button_example,text_view_status" />

The property app:constraint_referenced_ids contains a list of view ids that will form the barrier.


Chains allow you to control the space between elements and how the elements use the space. To create a chain, select the elements that you want to form part of the chain, and then right click – “Chain” – “Create Horizontal/Vertical Chain”.

Chains in ConstraintLayout Android
ConstraintLayout Chains

You are then able to cycle through the different chain modes. There are four different modes: spread_inside, packed, spread and weighted.

Different Chain Modes in ConstraintLayout

The XML for creating a chain is different in that all the views have the constraints defined on them and the first item in the chain specifies the chainStyle.

        tools:text="1" />


With groups, you can logically group together certain views. Don’t confuse this with normal ViewGroups in Android though. A group in ConstraintLayout only contains references to the view ids and not nesting the views inside a group. With a group, you can set the visibility of all views in the group, by just setting the groups visibility without needing to set every view’s visibility. This is useful for things such as error screens or loading screens where a few elements need to change their visibility at once.

To add a group – see below:

Groups in ConstraintLayout

If you are wondering how this looks in XML, here it is:

        app:constraint_referenced_ids="button_load,text_view_status" />

The property app:constraint_referenced_ids contains a list of all the view ids that need to be a part of the group.

Practical Example

I wanted to try recreate the Google Play Movies detail screen only using ConstraintLayout to see how much I could build in the UI Editor. The results completely blew me away.

ConstraintLayout Android Example
ConstraintLayout Android Example

For the code relating to this layout, checkout this Github repository.

There are loads more features in ConstraintLayout, so subscribe to the blog to receive updates. Have anything to add? Let me know on Twitter.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Android Oreo – (8.0) – Features I’m excited about

Android Oreo – (8.0) – Features I’m excited about

Google has officially announced the next version of the Android operating system and it is called Android Oreo! If you are a mad Android fanatic like me, then you probably already know this by now. Historically, Google has named its versions of Android after different tasty sweets or desserts, each version is named alphabetically – it started with Cupcake, Donut, to the more recent ones such as Marshmallow and Nougat. One of the big reasons why I love Android is because of the delicious sweet treats that the releases are named after.

There was a buzz of excitement at Google I/O 2017 this year with people trying to guess the next version name. Suggestions of Oatmeal Cookie, Oreo, Orange soda and some even suggested Ouma Rusks (okay I admit – that one was all me). On Monday the 21st of August, the announcement was made that Android O would be called Android Oreo!

Read More Read More

Resources for Getting Started with Modern Android Development

Resources for Getting Started with Modern Android Development

 After putting together resources for the Mobile Developer Graduate Program that we run at DVT, I realised that the content I referenced could be a great guide for getting started with Modern Android development.

It is worth noting that we have a very hands-on approach to training the graduates at DVT. We run workshops as well as practical projects to ensure our graduates have a solid understanding of Android development.

With the vast amount of content available online, when I started Android development I didn’t really know where to look or what I should be aware of when developing an app. Having a concise list like the one in this blog post would have been invaluable for me when I started out. I hope you find value in it too.

Here is a list of links, code labs and reference material that would be useful for any developer that wants to get started in the world of Android development.

Read More Read More

Android Architecture Components – Looking at Room and LiveData – Part 1

Android Architecture Components – Looking at Room and LiveData – Part 1

This week at Google I/O 2017, there were a lot of new announcements for the Android Platform. One of the announcements was the new architecture guidelines for Android! This is a welcome addition to the Android platform.

Previously the Android team refrained from giving advice as to how you should structure your Android applications. For the most part this meant that anyone learning Android for the first time would just end up placing all their code into the Activity files and occasionally moving stuff into an AsyncTask if the app crashed with a NetworkOnMainThreadException. Only after trying to add unit tests and instrumentation tests would you really understand that your code you have just spent so long developing was not easy to read, make changes to or to write tests for.

Read More Read More