Android ConstraintLayout & Friends30 May 2016
One of the most exciting developer-facing announcement at I/O this year was the introduction of ConstraintLayout. It is a new type of layout available in the Android support repository built on top of a flexible constraints-based system.
It makes it easy to create flexible user interfaces by allowing developers to declare constraints between widgets instead of having to use complex nested layouts. It is in many ways similar to AutoLayout on the iOS platform and is fairly easy to use, so I won’t go the details of how to use it. If you are unfamiliar with it, I highly recommend watching the following talk and going through this code lab.
While playing with
ConstraintLayout using v1.0.0-alpha1 of the Constraint Support Library, I noticed something called
LinearConstraintLayout. It doesn’t show up in the palette inside the layout editor, however it does comes up as a suggestion when you are creating a new layout. You can also add it manually in XML using the following tag —
It is a simple container that allows you to add equally-spaced widgets either vertically or horizontally, very similar to a
LinearLayout. You can set the orientation using the attribute of the same name in the app namespace.
Looking at the code, it just loops through its children and sets constraints on them based on the orientation so it should comparatively be more light-weight.
There’s also something called a
TableConstraintLayout in this version which presumably makes it easy to create table-styled interfaces, but the layout editor currently throws an error while trying to render it and the source code seems to be a work in progress.
Since the library is in alpha at the time of writing this, it’s fair to assume that these layouts are currently under development and we should get more details and documentation in the coming weeks. It is also possible that Google might decide to get rid of these layouts, so you shouldn’t use them in production.
I’ll update this post when more details are available.