Android dynamically changes Layout properties RelativeLayout.LayoutParams.addRule ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.