


The best place to understand this layout system is this dedicated web site that covers the basics behind constraints, chains, guidelines, dimensions, and barriers. ConstraintLayout combines the power of LinearLayout and RelativeLayout while sidestepping the need to create nested layouts. Google first introduced the layout system at the Google I/O conference in 2016 and has invested the past several years improving Android Studio to make it easier to build layouts with the visual editor. ConstraintLayoutĬonstraintLayout is Google's new default layout system. When creating View Layouts in code, beginners will often confuse the many different available LayoutParams classes and run into hard to catch problems. Keep in mind that each subclass of ViewGroup, such as LinearLayout, has its own nested static class LayoutParams that's a subclass of ViewGroup.LayoutParams. ViewGroup also contains the nested static class LayoutParams which is used for creating or editing layouts in code. That means it is perfectly legal to pass a layout such as LinearLayout as an argument for something that takes View as a parameter. Each of them subclass ViewGroup, which itself subclasses View. It's important to note the class hierarchy of these View Layouts. Most of what can be done in LinearLayout and RelativeLayout can now be done with a new layout system called ConstraintLayout.

The bread and butter layouts are LinearLayout, RelativeLayout, and FrameLayout. There are a few very commonly used layouts and then many more specialized layouts that are used in only very particular cases. Nearly all Android activities have layout containers similar to the way that most HTML documents use "divs" to contain other content. As Layouts are classes, you can build custom layouts by inheriting from them.Īndroid activities (screens) use layouts as a container for view controls, and layouts can actually contain other nested layouts as well. These layout classes (LinearLayout, RelativeLayout, etc.) are used to display child controls, such as text controls or buttons on the screen. This means that all the concerns of " where to place the View on the screen" is handled by Layouts, thus Layout Views are also the first level element in the UI tree hierarchy. View Layouts are a type of View class whose primary purpose is to organize and position other view controls.
