r/androiddev • 🎲play 💩fail 💪learn • Apr 24 '18

Article Introducing Constraint Layout 1.1 – Google Developers

https://medium.com/google-developers/introducing-constraint-layout-1-1-d07fc02406bc
231 Upvotes

26 comments sorted by

77

u/cilvet Apr 24 '18

Honestly, when I started developing for android 3 years ago I remember thinking "why can't I just set a percentage for the width and height?"

I never thought I would actually see that happen

47

u/MmKaz Apr 24 '18

PercentRelativeLayout existed 3 years ago

16

u/AsdefGhjkl Apr 24 '18

You could do it with weights, though yeah, it's a very welcome addition.

3

u/Cyrrus30 Apr 24 '18

Yes, but only in LinearLayouts..

2

u/Ayesuku Apr 25 '18

Built a calculator app recently just to familiarize myself with Android, ended up using a vertical LinearLayout of horizontal LinearLayouts with weights and such in order to map the buttons to equally fill various screens.

It worked, but at the time I was pretty surprised I couldn't just set a percentage. I'm glad to see that happening now.

19

u/MKevin3 Apr 24 '18

I have been using 1.1 features throughout the beta period. I reported a few issues and they have been fixed. Honestly never thought I would use the radius stuff but I did need it.

Pretty happy with CL 1.1 and have only found one area I could not use it. I had a vertical set of items and I was setting visibility of some in code hoping the ones below would move up / down based on ones above them. Turns out it gets lost at some point so I just put them in a dreaded TableLayout and it worked fine.

Need to do a sample layout and code showing the issue at some point and report it. Weird edge case.

5

u/Fr4nkWh1te Apr 24 '18

I still don't get optimizers

5

u/herpderpredditor Apr 25 '18

@ /u/nicolasroard: When you create a group and put some views in that group: why are the ids in

app:constraint_referenced_ids:"view1,view2,..."

just strings?

I've refactored some view-ids with Shift-F6 and those strings will not update automatically...

22

u/Tubzor1 Apr 24 '18 edited Apr 25 '18

Buggy as hell, update messed few of my layouts.

One example:

2 buttons, each should be half of the screen width,

width is set to 0dp on both, constraints are "parent" to both ends and buttons to each other respectively.

Worked on 1.0.2 without problems, on 1.1.0 it messed up entire layout, had to use new percentWidth constraints.

@Edit issue to track

https://issuetracker.google.com/issues/78547453

48

u/ZakTaccardi Android Developer Apr 24 '18

File a bug. This is why there are release candidates

20

u/nicolasroard Android Studio Design Tools / ConstraintLayout Apr 24 '18

Can you please file a bug with your XML layout -- I cannot reproduce this.

2

u/Tubzor1 Apr 25 '18

Filed issue to track

6

u/TurKorsaN Apr 25 '18 edited Apr 25 '18

Looks like the issue is inconsistency at the constraints that you use.

    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/right"

and

    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toRightOf="@id/left" 

use left-right or start-end constraints. You shouldn't mix them up.

1

u/[deleted] Apr 26 '18 edited Apr 26 '18
  1. These are generated by the layout editor. I don't remember ever writing them by hand.

  2. I am grateful to google for all the free software they make. But this a bug, not a feature because 1.

-1

u/Tubzor1 Apr 25 '18

Yes, but they have multiple options

1) disable it from the beginning and show warning in XML editor

2) support it in newer versions

3) announce that they drop support for mixes

I guess the best one would be first one, because it would not lead to confusions in the future

3

u/lacronicus Apr 25 '18

Just because it happened to work doesn't mean it was ever really "supported".

3

u/diceroll123 Discord mod Apr 24 '18

Same here, except instead of using percentWidth I just went back to 1.0.2 for now.

2

u/superfebs Apr 25 '18

Wondering if a similar thing will ever come to Flutter 🤔

1

u/Fr4nkWh1te Apr 25 '18

Can anyone give me an example of a custom transition when applying ConstraintSets in Java? I only found Kotlin examples and I have no clue about transitions and animations, so I don't know what the corresponding Java classes are.

0

u/zotikola Apr 25 '18

This layout is not easy to use. Went back to classic ui

2

u/[deleted] Apr 25 '18

Were you using XML or the GUI editor?

2

u/zotikola Apr 25 '18

Tried them both. I like more the xml editor, but the selling point of this layout was the visual ui editor.

I am sure i may be missing something, and all i need is a very complex tutorial

3

u/Eeshoo Apr 25 '18

Felt the same way in the beginning but after working on a few screens it felt very natural.

1

u/LindtChocolate Apr 25 '18

I think caster.io had a decent tutorial. I don't remember if it was free though, but it was quick and thorough, a nice introduction to it.

2

u/baggyrabbit Apr 25 '18 edited Apr 25 '18

You should see a performance boost with ContraintLayouts because they allow for a flat view heirarcy.

You should give it another chance.

0

u/[deleted] Apr 25 '18

[deleted]

4

u/fear_the_future Apr 25 '18

Is anything in the android UI framework?