Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ConstraintLayout 2.0

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

ConstraintLayout 2.0

Talk about the already released and upcoming features of ConstraintLayout 2.0 held at the GDG Nuremberg Meetup (https://www.meetup.com/GDG-Nuremberg-Android/events/xsfbcpyxkbgb/).

The talk actually included some live coding and another demonstration in the emulator and in Android Studio. Alas, for obvious reasons, those cannot be uploaded :-)

An abbreviated version of the talk has also been given in Utrecht at the Dutch Android User Group's IO Extended Extended (https://www.meetup.com/dutch-aug/events/251987429/) on July, 19th 2018

Avatar for Wolfram Rittmeyer

Wolfram Rittmeyer

July 24, 2018
Tweet

More Decks by Wolfram Rittmeyer

Other Decks in Programming

Transcript

  1. ConstraintLayout 1.0 • Flat layout hierarchies were overarching aim •

    Allows you to design views by putting them into relation • match_constraint instead of match_parent • Support for aspect ratio constraints • Guidelines to helps you design screens @RittmeyerW
  2. ConstraintLayout 1.1 • Two helpers: – Barriers – Groups •

    Chains for grouping views • Introduction of ConstraintSet • Addition of percentage for width / height @RittmeyerW
  3. Google IO 2018 • Many announcements • Currently available: –

    Alpha version of CL 2.0 available – Some layout editor changes in AS https://www.youtube.com/watch?v=ytZteMo4ETk https://www.youtube.com/watch?v=WxAZk7A7OkM @RittmeyerW
  4. API

  5. Alpha version • Build.xml: • For now ties you to

    support lib 27.0.2 implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1' @RittmeyerW
  6. ConstraintHelpers to manipulate views • Get access to the list

    of views the manage • They are no ViewGroups – Views are referenced but not proper children • Help you to manipulate multiple views easily – e.g. animations • The ConstraintHelper class itself is not new – Was used in Barrier and Group before @RittmeyerW
  7. Fluent API for ConstraintSets • Idea is to make handling

    of ConstraintSets easier – Easily create ConstraintSet – Easily manipulate all attributes @RittmeyerW
  8. Switch easily between diferent states • Define states with ConstraintLayoutStates

    • Use subelement State to refer to layouts • In your code set the state to use @RittmeyerW
  9. Other animation types still relevant • Property animations • Physics

    based animations • Animated Vector Drawables • CoordinatorLayout • Transitions @RittmeyerW
  10. MotionLayout is about transitions • Define diferent states • Use

    handlers to transitions between those states • Use key frames to help guide the animation @RittmeyerW
  11. Use MotionLayout to define elements • MotionLayout replaces ConstraintLayout •

    MotionLayout points to scene • All layout children must be present @RittmeyerW
  12. Specify the transition • Add a Transition element to your

    MotionScene • If necessary add a touch handler – OnClick – OnSwipe @RittmeyerW
  13. Specify the trigger for the transition • If necessary add

    a touch handler – OnClick – OnSwipe @RittmeyerW
  14. Animate custom attributes • Animate not only layout attributes but

    also others • Types: – Boolean – Color – Dimension – Int / Float – String @RittmeyerW
  15. Add keyframes for special efects • If you want to

    move your layout along specified paths • You can specify when the frame should be applied @RittmeyerW
  16. Not everything is possible (yet?) • Currently only one transition

    • Touch handler reacts too generous • Image handling requires special subview • „left“ and „right“ instead of „start“ and „end“ • No drawables for custom attributes • Auto complete in XML not working (properly?) • Errors in XML are ignored @RittmeyerW
  17. Nice helpers • Convert View (for Views and ViewGroups) •

    Navigation to included layout @RittmeyerW
  18. Create nicer list previews • List item layout (you were

    already able to do that) • No of items • Sample data – For images and text – Define your own in xml or as json – Use predefined ones @RittmeyerW