Android development-Dynamic Layout note, android note

Source: Internet
Author: User

Android development-Dynamic Layout note, android note

Compared with static la S, android dynamic la s do not need to change xml to layout code, which improves the efficiency. Of course, you can ignore it. The Dynamic Layout is mainly flexible. You can quickly modify the layout in the Code and directly use controls for business logic development. However, the amount of code is usually large, so it is not convenient to maintain the static layout. However, as an android developer, mastering certain dynamic layout skills can also improve code development efficiency at work.

In the dynamic layout, to achieve a layout, it is generally the first to create five layout objects. Set the attributes of these objects, and then add sub-la s or controls to them.

Take RelativeLayout as an example.

RelativeLayoutMLayout= New RelativeLayout ();

// Set the child control property object of RelativeLayout and set its size style. Each GroupView has a LayoutPrams, which is used to set the child control.

RelativeLayout. LayoutPramsParams= New RelativeLayout. LayoutPrams (LayoutParams. WRAP_CONTENT, LayoutParams. WRAP_CONTENT );

// Add a child Control

ImageView iv = new ImageView (getActivity ());

    Iv. setImageResource (R. drawable. tab_icon_conversation_normal );

// Set the position attribute of the subcontrol in RealtiveLayout.

Params. addRule (RelativeLayout. CENTER_IN_PARENT, RelativeLayout. TRUE); // adds an attribute to iv

    // Add iv to mLayout

    MLayout. AddView (iv, params );

From the last sentence, we can see that all the attributes set by the params object reference apply to the sub-control ImageView, and then add iv and params to RealtiveLayout.

Related Article

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.