Skip to content

androidx.constraintlayout:constraintlayout

Official Description: ConstraintLayout for Android

CommonsWare's Notes

ConstraintLayout is the primary option nowadays for constructing an Android UI, in terms of controlling where individual widgets are positioned on the screen and how they are sized.

ConstraintLayout is very flexible, allowing you to position widgets relative to:

  • Each other
  • The edges of the ConstraintLayout
  • Guidelines (invisible lines used solely for positioning rules)
  • Barriers (guidelines tied to collections of widgets)

You can easily set a widget's horizontal or vertical size to be wrap_content (to be sized based on the widget's contents) or 0dp (to be stretched to fill the space between two anchoring points along the requested axis).

Compared to legacy containers like LinearLayout and RelativeLayout, ConstraintLayout offers more functionality and (frequently) better performance.

Documentation

Knowledge

Samples

  • Exploring Android: CommonsWare's hands-on tutorial book builds a complete app from scratch, including using ConstraintLayout for the layouts
  • Sunflower: A gardening app illustrating Android development best practices with Android

Versions