Layoutparams inherited from Android.View.ViewGroup.LayoutParams (ext.)

Source: Internet
Author: User

Layoutparams is equivalent to a layout information package that encapsulates the location, height, and width of the layout. Suppose that an area on the screen is occupied by a layout, and if a view is added to a layout, it is best to tell the user how it is intended to be laid out, that is, to pass in an approved layoutparams.
Can describe Layoutparams, on the chess board, each piece occupies a position, that is, each piece has a position of information, such as this piece in 4 rows and 4 columns, where the "4 Rows 4 Columns" is the layoutparams of the pieces.

But the Layoutparams class also simply describes the width of the height, width and height can be set to three kinds of values:
1, a definite value;
2,fill_parent, which is filled (as large as the parent container);
3,wrap_content, that is, wrapping the components is good.

The layouts that are dynamically built in Java are often written like this:

Setlayoutparams (New Layoutparams (Layoutparams.fill_parent, layoutparams.fill_parent));

The above sentence is actually a child to the father, that is, the parent layout under the child control to set this sentence.

Because the layout is many, although all inherits to the ViewGroup but each layout still has the very big difference.

It is clear that the above sentence should be written in such a way as to be accurate:

Setlayoutparams (New Tablerow.layoutparams (tablerow.layoutparams.fill_parent,tablerow.layoutparams.fill_parent)) ;

This means that the parent layout of this child control is a TableRow, so there are too many layoutparams, so it should be clearly specified.

Below are the next two common to the layout:

1. Framelayout the dynamic setting of the child control Center, the dynamic use of Java code to achieve this:

Framelayout.layoutparams LYTP = new Framelayout.layoutparams (80,layoutparams.wrap_content); lytp. Gravity = Gravity.center;btn.setlayoutparams (LYTP);

2. Relativelayout the child control Center under Dynamic settings:

Relativelayout.layoutparams lp=new Relativelayout.layoutparams (layoutparams.wrap_content,layoutparams.wrap_ CONTENT); Lp.addrule (Relativelayout.align_parent_right, relativelayout.true); Lp.addrule (Relativelayout.align_parent_top, relativelayout.true); BTN1.SETLAYOUTPARAMS (LP);

Layoutparams inherits from Android.View.ViewGroup.LayoutParams (go)

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.