"Android" does not know the Setlayoutparams

Source: Internet
Author: User

When creating layout dynamically, Layoutparams is the parameter that must be set, how much does setlayoutparams know about it?

    1. 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.

    1. 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

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.