ConstraintLayout is a layout method recommended by Android Studio that enables flexible layouts that reduce nesting between controls and optimize the rendering performance of an interface.
Official documents:
- ConstraintLayout
- Build a Responsive UI with ConstraintLayout
ConstraintLayout LinearLayout, RelativeLayout layout, ConstraintLayout layout can be implemented, and the layout is lighter, flatter.
For example, to achieve the following layout, an icon and a piece of text are centered, and the text length is not fixed. What do you need to do?
Previously, we might have used the following implementation, nesting a layer of LinearLayout to wrap the elements in the center. The result is fine, but it is not the optimal solution.
ConstraintLayout makes everything simple. There is no need to nest a layer, and you can directly add constraints to elements. Both are integrated with Packed, making the layout more flat.
This is the ChainStype attribute of ConstraintLayout, the Layouting-weight attribute of LinearLayout is also included, and you can specify the ratio of the left and right margins. It’s so flexible and powerful.
GuideLine, Barrier, Group, PlaceHolder, etc. support relative positioning, Angle positioning, proportional size constraints, ConstraintLayout, ConstraintLayout, etc.
In addition, as you can see from the Layout Editor of Android Studio, controls from Legacy are officially deprecated, including ListView, GridView, RelativeLayout, and so on. ConstraintLayout, LinearLayout, and FrameLayout are all Layouts, and RecyclerView is all you need. In the selection of controls, there is no best, only the most appropriate.