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)