ConstrintLayout was used very frequently in the previous project. I did not notice that in some layout design process, there are more or less some layout nesting redundant scenes;
ConstrintLayout would have nested a LineraLayout layer around the 3 items, and chain_2 would have set marginStart a distance
Thus, chain_1 and chain_2 are separated, but chain_2 and chain_3 are together;
Admittedly, there is nothing wrong with this scheme, but for performance considerations, there is still a layer of nesting layout, or flaws, if there is a lot of nesting, it is a nightmare for low-end phones; Plus, you use your app every now and then
Memory leak, leak more, the user does not kill the process, over time, stuttering is necessary;
So, for Andorid, performance is very valuable, in order to find a case, solve a case principle, there is still need to optimize;
ConstraintLayout the internal elements form a chain when they are laid out.
Commonly used are:
layout_constraintStart_toStartOflayout_constraintEnd_toEndOflayout_constraintTop_toTopOflayout_constraintBottom_toBottom Of, etc.
This time I want to talk about:
layout_constraintHorizontal_chainStyle
layout_constraintVertical_chainStyle
Take layout_constraintHorizontal_chainStyle for example:
This property has three properties: spread (default), spread_inside, and Packed
Spread:
Three are equal width, the two ends of the distance from the left and right sides of the boundary is also a distance;
spread_inside
The difference from spread is that there is no boundary between the two ends and the left and right sides, that is, chain_1 and chain_3 have no gap with the parent layout.
packed
The three elements in the chain will be tied together
To achieve this effect, set layout_constraintHorizontal_chainStyle to the head of the chain (only for chain_1, not for chain_2 and chain_3).
Guideline:
A helper line provided as constraintLayout
We can see this from its package name; It defaults to gone and provides the main function
For auxiliary layouts, similar to guides, you can set the Android: Orientation property to determine if it is landscape or vertical. When vertical, the Guideline width is 0 and ConstraintLayout height is parent. When horizontal, the Guideline height is 0 and the width is parent
The more common attributes are as follows:
Layout_constraintGuide_begin, constraintguide_begin, specifies a fixed distance to the left or top, such as 100dp, and a helper line appears at 100dp to the left or top. Layout_constraintGuide_end, specifies a fixed distance to the right or bottom, For example, at 30dp, a helper line, layout_constraintGuide_percent, appears at 30DP to the right or bottom, specifying the percentage of width or height in the parent control, such as 0.8, representing 80% of the distance to the top or left.
I use:
Layout_constraintGuide_percent = 0.5, chain_1, bottom layout_constraintBottom_toTopOf, relative to guildeline.
In a word:
Interpret Layout These two attributes are handy to use, and should be used more often in the future