When creating layout dynamically, Layoutparams is the parameter that must be set, how much does setlayoutparams know about it?
- The Setlayoutparams is set to the parent node.
The document says clearly:
Set the layout parameters associated with this view. These supply parameters to the parent of this view specifying how it should is arranged. There is many subclasses of
Viewgroup.layoutparams, and these correspond to the different subclasses of ViewGroup, is responsible for arranging t Heir children.
This means that the setlayoutparams () is for its parent control, and only the parent can change the placement of the child view, rather than the child view being set at will.
-
The Setlayoutparams type cannot be given casually.
It is clear that Layoutparams is set according to the parent node, although the creation of a viewgroup.layoutparams can be successful when used, but it is also defined as the type of the parent node as the specific Relativelayout.layoutparams, Linearlayout.layoutparams, etc., or it will throw an exception when running.
Relativelayout.layoutparams layoutparams= New Relativelayout.layoutparams (RelativeLayout.LayoutParams.WRAP_ CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
Layoutparams.addrule (relativelayout.center_in_parent);
View.setlayoutparams (Layoutparams);
"Android" does not know the Setlayoutparams