Android development tips: Constraint Layout helpers II. part
Technology
5
 min read
April 19, 2021

Android development tips: Constraint Layout helpers II. part

Peter Šuly
Peter Šuly
Android developer

I brought you the second part of an article about Constraint Layout Helpers, which are type of ViewGroup, which allows you to create complex layouts. Full power of Constraint Layouts comes from his helpers, so i've prepared the article about them.

In the first part of the introduction to Constraint Layout Helpers, I introduced Group, Guidline, Layer and Barrier. If you haven't seen them yet, don't forget to visit the first part!

Placeholder

Placeholder is helper which can help to position another views (that's where it's name comes from - it's "holding place" for view). When you call setContentId() method on placeholder object somewhere in your code, placeholder objects become the content view. If content view exists on the screen already, it will be treated as gone on its original location after setContentId() call.

E.g. when some of the upper circles is clicked, placeholder.setContentId() is called, placeholder becomes the clicked view (clicked view moves to placeholder's position, inherits placeholder's constraints).

Don't miss my #goodroidtips I. or II. ,articles about useful tips and tricks for Android developers.

Flow

Similar to Group, Flow takes views ids into constraint_referenced_ids attribute and automatically creates Chain behavior between them. Chain behavior (way how views overflow the Flow) is determined by wrapMode attribute of Flow.

As we said, Flow automatically creates chain between it's elements. Chain style can be configured by flow_horizontalStyle or flow_verticalStyle attribute based on Flow's orientation. Behavior of chain style is basically the same as for chains.


First and last chain in the Flow can have different style attributes  as others e.g. for the first chain we define flow_firstHorizontalStyle="spread_inside" for the last chain we define flow_lastHorizontalStyle="packed". All the others chains in the middle took default flow_horizontalStyle="spread" because we did not defined anything.


Flow can be customized by many other attributes e.g.

Bonus

Circular positioning

Circular positioning attributes allows you to constraint view to another view at specified angle and distance. Important attributes when we want to circularly position views are

E.g. positioning image1, image2 and image 3 around baseImage in 0, 45 and 90 degree.

Resources: https://developer.android.com/reference

Like what you see?
Join our newsletter.

Great! Welcome to newsletter.
Oops! Something went wrong while submitting your email.
High quality content once a month. No spam, we promise.
Your personal data is processed in accordance with our Memorandum on Personal Data Protection.

Páči sa vám náš content?
Odoberajte newsletter.

Great! Welcome to newsletter.
Oops! Something went wrong while submitting your email.
Vaše osobné údaje sú spracované v súlade s našim Memorandom na ochranu osobných údajov.