We know that there are many special properties in the Relativelayout layout, which are usually statically set in the relevant XML file before loading the layout.
However, in some cases, we need to dynamically set the layout of the properties , under different conditions to set different layout arrangement, it is necessary to use the RelativeLayout.LayoutParams.addRule () method , which has two overloaded methods:
addRule (int verb): When this method is used, the properties of the set node cannot be associated with other sibling nodes or the property value is a Boolean value (a Boolean value property , which is set to True, the default is False if not set ), for example: AddRule (relativelayout.center_ VERTICAL) means that the corresponding node in the relativelayout is vertically centered.
AddRule (int verb, int anchor): The property of the node set by the method must be associated with another sibling node or the property is a Boolean value (when the property is a Boolean value , anchor for Relativelayout.true indicates that True,anchor is 0 for false), for example: AddRule (Relativelayout.align_left, r.id.date) means The corresponding node in the relativelayout is placed to the left of a sibling node with an ID value of date.
Basic Process Examples:
// ... ... View view = Parentview.findviewbyid (r.id.subject); params = (relativelayout.layoutparams) view.getlayoutparams (); params // or Params.addrule (relativelayout.center_in_parent); View.setlayoutparams (params); // ... ...
In this way, you can dynamically change the properties of the layout in adapter
Android dynamically changes Layout properties RelativeLayout.LayoutParams.addRule ()