Thoughts on Android Studio’s New Design Editor
Wolfram Rittmeyer reviews his likes and dislikes regarding the new layout and editors introduced at Google IO.
Join the DZone community and get the full member experience.Join For Free
at this year’s io google introduced a new layout – the constraintlayout – and also presented it’s totally revamped layout editor. i am not going into how to use the layout. google itself has done a good job in explaining it with its code lab “using constraintlayout to design your views” .
in this post, i highlight what i like about the new layout and the new editor.
what’s to like about the new constraintlayout
with the new layout, there’s a lot to like. here are my favorite things about it:
- the aim is to help developers
- the availability of the stretched width/height of its children
- the use of guidelines
- the fact that is doesn’t feel as weird as auto layout
now let me dig a bit more into each of these.
the aim to help developers
- to make handling complex screen designs easier
- to improve the performance of complex layouts
and both are, of course, highly appreciated.
if you have a complex layout, things can get pretty difficult to manage. moving stuff around in a
is bound to break a lot of other stuff. that’s what they cited at io, and it is true. so if this new layout helps us with this, i’m all for it.
on the other hand, things aren't currently as bad as they made them out to be. and the nesting can actually help you understand certain parts of the layout better since they are grouped and broken down into smaller parts. more practice with the new layout will show if this really makes that much of a difference when maintaining screens.
in my opinion, the second motivation is more important: to improve the performance. as users we all want the apps on our devices to run as smoothly as possible, and as developers, we want to deliver this experience to our users. thus, i’m all for it.
when it comes to performance improvements there is never any limit for additional improvements. so if google helps us, i’m more than happy. maybe this way the
also reduces the need for some custom views or layouts.
a bit down i’m going to have a look at the actual performance of the
as it is today
. it definitely needs more work, but the goal is laudable and the final implementation surely will fare much better than the current one. mind you, we are talking about an alpha version here!
the availability of the stretched width/height of its children
the new stretched (or “any size”) appearance is better than
in the context of this new layout. by stretching to its constraints this new mode is not limited to the enclosing container but can be used for arbitrary areas of the screen. you could achieve this with other means before – but now we have a unified concept for everything, which sounds more logical to me. it’s not that big a change, but a nice one nonetheless.
guidelines are great additions
in addition to the layout and the editor, we also have guidelines. these only make sense in the context of the
– but they are actually proper views. they show up as separate view items in the hierarchy and get rendered at runtime.
but fear not. the decompiled guideline class is not only a mere 44 lines short – it also is as simple as a view can get. it doesn’t draw anything, always sets the dimension to zero width and zero height in its
method and on top of that sets itself to
in the constructors. so no problems there.
what this means is that the guidelines can work as any other view when it comes to constraints.
for the placement of the guidelines you can use fixed values (say always 100 dp from the left edge) or percent values (say always at 33% of the whole screen width).
later on in this post, i am going to show you a sample for how to make good use of guidelines.
not as weird as auto layout
when i first heard about the new layout during the io keynote, my first thought was, “oh no! auto layout is coming.” i have not done much with ios, but what i have seen of auto layout - well, let’s put it this way: i do not necessarily like it. it breaks too easily whenever you try to do something with the screen. it’s only partially intuitive. in short, it’s nothing you like to work with.
right now i do not have these negative thoughts when it comes to
. maybe google learned something from what apple did wrong. but it could as well be that it’s just because
is not (yet?) as powerful as auto layout. i don’t know – all i can say is, that
seems to behave quite reasonably. but seasoned ios devs might think about this issue very differently.
what’s to like about the new editor?
the new editor, of course, is also part of google’s plans to make life for us developers easier. actually, it might end up to be also quite useful for sketching and prototyping. who knows?
i especially like these things:
- the properties pane has improved a lot
- the editor shows lint warnings and errors prominently
the editor supports all kind of
viewgroups– not only
- everything is still xml backed
- the screen is easily resizeable
the editor lets you select an image for all
the improved properties pane
do you remember the old properties pane? all kind of attributes were listed in an alphabetical way. only very few more important properties were at the top:
now this has changed significantly – and it is much more usable that way:
android studio by default lists only important and often used properties in this pane. though if you feel like it, you can always go back to the old list by clicking on the "show expert properties" button on the top right.
some attributes probably should be added (like
), but all in all, this is much better than before.
also note that for views that extend other views, the properties pane lists the properties grouped by the class they originate from. in this case, first those of
and afterwards those of the inherited
the error hints
another nice addition we haven’t had before is the prominent display of lint errors and warnings in glaring red, so that you can’t miss them:
and if you click on the number, it expands to show the problems:
and as you can see, it also shows the content of the view in question, so that you know right away which view has a problem. nice!
the new editor supports all kind of viewgroups
when google introduced the new layout editor it only showed it with the
. but you will be able to use it for all existing layouts as well. for
this works well, for
not so much. for
some magic of the
(like dragging to which other view the new view should be relative to) would make sense as well.
i guess google puts more emphasis on correctly supporting
than supporting the other layouts like
. actually, i hope so. i very rarely used the designer with those older layouts. i preferred the xml view and expect this to remain unchanged for those. and for those “legacy”
types i wouldn’t mind if it stayed like that. after all the idea is to get rid of them anyway.
everything is still xml backed
obviously the aim of google is for us to use the layout editor instead of the xml editor in the future. so why then is xml still a big deal?
in my opinion there are a few reasons:
- xml is better to fix fiddly things sometimes working with a graphical editor has its drawbacks and it can become pretty difficult to access the correct handle and drag it onto the correct drop target. or you made a mistake and marked some views as invisible or gone – or made them ridiculously small.
- xml is ideal for version control with a simple diff you can quickly see what changed over time. this is nice for you (using your local history or comparing changes to previous versions), but is even more important when collaborating with others. code reviews, reasoning, and discussing pull requests is so much easier with xml and line numbers than having to throw screenshots around or having to run stuff just to understand even the simplest changes.
easy resizability of screen
at the bottom right corner of the screen, you have this handle. nearly too unobtrusive:
you can use this handle to drag and resize the current preview screen and see which influence this has on your layout. probably not often needed, but it can come in handy – while creating your layout, but also during presentations and trainings.
the editor lets you select an image for all imageviews right away
whenever you drag an
onto the layout, the editor pops open a dialog in which you can choose the image to show or the color to use. that might not save
work, but it’s still a nice detail that i appreciate:
note that this screen also shows the more likely ones (the images of your project) at the top.
what about performance?
since performance improvements are among the main reasons to create this new layout, i did some performance tests to check if this goal is met.
i compared a layout used within a
. nothing too fancy, just some nested
containers. i moved this layout manually over to
and did some rather sloppy performance tests.
comparing those two on an emulator as well as on a nexus 5 yielded overall a performance penalty when using the new
performing worst is the measurement. the
method takes roughly ten times as long as the one of the
i used for comparison. and it uses up the bulk of the time with taking about 60 times as long as
. thus the 30 per cent hit of the
compared to the one of the
in question is nearly irrelevant. finally, layout inflation also took longer with
does lots of calculations to find out where and how to display each of its children. internally (at least) three rather lengthy classes are working together to get the results:
. to fully understand the performance behavior i would have to dig into the depth of these classes (and for this i prefer the commented classes when their sources are released by google). but just by having a cursory look at the decompiled code it looks like those classes have to do
right now it looks like the performance improvements that google hopes to achieve are far off. but at the google io talk john and nicolas mentioned that they are working hard on improving the performance. so we can expect this to get better over time. and since the
comes as a separate library, further improvements are likely even after the final release. if the result will be good enough in the end – well, that remains to be seen. we have to wait for future releases. and we have to do some more (and more thorough) testing with multiple layouts. right now i’m more than willing to give google the benefit of the doubt.
not all is working perfectly at the moment, though. right now these things bother me the most:
- there’s a noticeable lag between blueprint changes and design preview changes
- the preview is not always correct
- the blueprint view doesn’t heed text layout constraints
- constraints do not always work as expected
- undo works very unreliably
- the editor undoes stuff or changes stuff in unexpected ways
noticeable lag between blueprint changes and design preview changes
on bigger screens it’s quite useful to open the blueprint view and the preview next to each other. if you use lots of stretched views or many views that make use of the bias you will notice a growing lag in the preview.
this has already improved a bit with the latest updates, but is still noticeable and sometimes a bit irritating. also while calculating those new positions the editor makes heavy use of your cpu. luckily only for short bursts.
preview is not always correct
when you miss some constraints, the preview view shows an incorrect screen. this actually is by design and has been different in the very first version of the layout editor. back then (due to the aforementioned lag) things jumped around seemingly haphazardly, which of course was very disturbing. but apart from the lag, the other reason for this was that you can use the preview to drag things around (which i strongly advocate against - see below). there’s no reason for that. we have the blueprint editor to edit constraints. let the preview do what its name implies.
blueprint view doesn’t heed text layout constraints
this is a fairly minor issue, yet one i would like to see corrected. in a
setting the gravity doesn’t change the location of the text in the
view. the setting is reflected correctly in the design preview, but when working with the blueprint only, it feels odd that changing this setting doesn’t have any effect. switching between the design and blueprint view just to verify that this setting did indeed work as expected is a bit cumbersome. nothing that makes life really hard, but something that requires an extra step and makes one wonder at first.
constraints do not always work as expected
the following screenshot admittedly show a very weird and pretty useless screen – but it shows that constraints might not work as you would expect them to work:
never mind that this screen is among the weirdest app screens you might ever stumble upon. it still should be correct.
as you can see the bottom button is left-aligned to the right button in the second row. that’s at least how the button should be. and you can also see that this button is stretched. so why then does it stretch that far to the left? what makes this calculation go that wrong? my guess is that the problem is not so much with the button at the bottom, but the buttons of the second row.
what worries me is not that this specific screen isn’t working. the problem is that i do not know why it’s not working and what makes views appear so wrongly aligned. as long as things like this can happen, you are bound to run into this problem with a real screen on a real device eventually. and then it is really bothersome.
undo works very unreliably
on one screen i accidentally moved one view around after i set some button’s visibility to gone and to visible again. i hit ctrl-z and the button’s visibility changes to gone again. what i had expected, of course, was to undo the last step – which was the accidental dragging of another view.
trying to reproduce exactly these steps for this post i was not only not able to reproduce this particular problem. instead i was now not able to undo the moving around step. alas, very unpredictable again.
one of the earlier versions also behaved differently when using undo via the menu or hitting ctrl-z. this appears to be fixed in the current version. but since undo is so unreliable in general i do not know for sure.
i think this is the worst problems the editor has right now. when working graphically to quickly test stuff, moving items around should be easily – and reliably – reversible. otherwise this editor hampers experimentation and is not useful for quickly sketching and for trying things out.
the editor undoes or changes stuff in unexpected ways
this is even harder to describe properly since this seems to be even more haphazard than the undo issues. i do not have many proper examples.
on the screen i have worked with while checking and re-checking some stuff for this post i had a button. i changed the visibility to gone, then to invisible, and then to visible. afterwards, the view was still drawn as if it were invisible. reproducible? of course not.
the editor also tends to ignore size changes (or to revert them when switching between the xml and then back to the design tab). but none of this is easy to pin down and reproducing these issues is unreliable as well.
i do not envy the googlers having to fix these type of arbitrary issues. and i am sorry for not being able to be more specific. but whoever uses the editor will stumble upon the undo and unreliability issues pretty quickly.
suggestions for additions
currently i have two suggestions for the layout and three for the editor:
- add width constraints based on other views
- add an aspect-ratio constraint
- add ctrl-mousewheel scrolling to the layout editor
- allow changes in the blueprint view only
- make the guideline’s orientation indicator select the guideline
of course there might be more suggestions in the future when i’m actually going to use
for productive projects. but right now i think those additions would help a lot.
now let me tell a bit about why i would like to see those items realized.
add width and height constraints based on other views
for some screens i would like to ensure that neighboring elements use the same width (or height) – but not a fixed width. for example, you want buttons to divide up all of the width available. or two images next to each other.
you would simply set the layout’s width to
and then use
on its children and they would divide up the available space.
when i first experimented with
i thought it would be easy. simply use three buttons next to each other, align each of the right ones to the one left of it and finally the left button to the left edge of the screen and the right one to the right edge of the screen. and then make all of them stretch. but this didn’t work as expected:
what you see here is that the first two are as they would be with a width of
and only the last one is actually stretched. in a bug report i filed, a googler remarked that this works as designed. stretch doesn’t divide up the remaining space between all stretching views. keep this in mind!
but not all is lost: the team plans to add some constraints that would allow us to do this
in the future
the first release of
. the bad news is that we do not have this right away. the good news is that they have much more plans for this layout and that we can expect it to get better over time.
guidelines to the rescue
but even with the first release not having width constraints, we might be able to achieve this depending on the specific layout at hand.
for the layout shown above the solution is to use guideline objects to divide up the space and then align the buttons to it. here’s what the workaround looks like:
and since sometimes code is easier to understand, you can find the code for this layout in this gist . the gist contains the correctly sized buttons as well as the first attempt without guidelines.
add an aspect-ratio constraint
even though i never published it, i once made a board game. for things like this, it would be nice to have the ability to ensure that this view always has the same height as its width. and i can also imagine other use cases where elements should use a certain height depending on the device width. say half the height as the view’s width.
you can achieve this with custom views (and in the case of game boards that’s the most logical thing to use anyway), but i still guess this addition could make a lot of sense. especially for
whatever one might think of auto layout, there’s a reason apple provides it there.
make the guideline’s orientation indicator select the guideline
if you add guidelines they get an indicator at the top (or on the left for horizontal guidelines) which show whether a guideline is positioned at a fixed margin or at a percentage of the total width. here’s the indicator for a percentage:
it would feel more natural if i could select the guideline by clicking on this indicator. right now i first have to select the guideline by clicking somewhere on the line itself. afterwards i can use the indicator to drag the guideline around or to change the type of indicator. why not directly so?
add ctrl + mouse wheel scrolling to the layout editor
the layout editor can get very crowded – depending on a number of views, how close they are, and how they are constrained. in some cases, it would be convenient to quickly zoom into the screen, do some designing, and then quickly zoom out again. it also would be really helpful while presenting about the editor and the
this is what we’re used to when using graphics software. and android studio has a setting to allow this way of zooming for text:
ctrl + mouse wheel setting for text in android studio
thus i would like to see the zooming to work for the layout editor whenever this setting is checked in android studio.
allow changes to be made in the blueprint view only
currently it’s possible to change layout settings in the blueprint view – but also in the preview view. i think the latter should not be possible at all. restrict designing to the blueprint. if you do so, the preview would be less cluttered – and also might perform better.
the most important reason (in my opinion) is that we are then free to actually use the preview as it should be: a realistic preview. i have already mentioned that the preview is not correct in all cases. and this has to do with the fact that you should be able to drag views around there as well. but if we drop the need for this, we actually can see problems like missing constraints right away.
what about linearconstraintlayout and tableconstraintlayout
i just had a cursory look at both. thus i do not have an opinion on them. maybe in some later post. depends on how they turn out.
one thing is worth mentioning, though: those two layouts exist, but google doesn’t explain them at all. i think they didn’t even mention them during their io talk. so that’s the one thing i
say: please let us know what you intend to do with these
children and what they should be useful for. i actually have a hard time seeing much use of
for example – but hopefully google proves me wrong.
does anko support constraintlayout?
for those that use kotlin and like to use
as an alternative to xml, the answer right now is "no!". anko doesn’t support
to sum things up
the new layout and the new layout editor both show promise. they are currently in alpha (the layout) or preview (the editor), so we can expect to see many (if not all) of the problems ironed out until the final release of both of them.
it’s definitely worth getting yourself accustomed to the new layout. i’m quite confident that it is the future.
having said that, i
don’t use the
for real projects. but i expect to be able to do so pretty soon.
please note that everything i have written here is based on what i
think about the
and the design editor. there have been lots of improvements during the last iterations of both the
and the editor and i expect this to go on.
also keep in mind that we are only starting to understand the possibilities of
! the more we use it the more we will know how to do stuff. i’m actually quite excited about it – despite some of the problems the alpha still has.
i very much appreciate what the googlers are doing there! keep up the good work – and thanks!
Published at DZone with permission of Wolfram Rittmeyer, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.