Android Development-Dynamic layout notes

Source: Internet
Author: User

Android dynamic layout compared to static layout, dynamic layout does not have to transform the XML layout code, improve a certain efficiency, of course, can be ignored do not remember. Dynamic layout is mainly flexible, can quickly modify the layout directly in the code, and directly use the control for business logic development. However, the code size is usually larger, and maintenance is not static layout convenient. However, as an Android developer, mastering a certain dynamic layout skills, and sometimes in the work can also improve the efficiency of a certain code development.

In a dynamic layout, to implement a layout, you typically create the first five layout objects. The properties are then set for the objects, and then the child layouts or controls are added to them.

Take Relativelayout as an example.

Relativelayout mlayout = new Relativelayout ();

Sets the child control Property object for Relativelayout and sets its dimension style. Each groupview has a layoutprams that is used to set the child control to occur.

Relativelayout.layoutprams Params = new Relativelayout.layoutprams (layoutparams.wrap_content, Layoutparams.wrap_content);

Adding child controls

ImageView IV = new ImageView (getactivity ());

    Iv.setimageresource (R.drawable.tab_icon_conversation_normal);

Sets the position property of the child control in Realtivelayout.

Params.addrule (Relativelayout.center_in_parent, relativelayout.true); Add attribute to IV

    Add IV to Mlayout

    mlayout . AddView (iv, params);

From the last sentence, it can be seen that the params object reference set properties are ImageView on this child control, and then add the IV and the params piece into the realtivelayout.

Android Development-Dynamic layout notes

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.