Linearlayout.layoutparams
Extends Viewgroup.marginlayoutparams
| java.lang.obj ECT |
|    ? |
android.view.viewgroup.layoutparams |
|   |
   ? |
android.view.viewgroup.marginlayoutparams |
|   |
  |
   ? |
android.widget.linearlayout.layoutparams |
| Known Direct subclasses Radiogroup.layoutparams, Tablelayout.layoutparams, Tablerow.layoutparams |
Layoutparams inherits from Android.View.ViewGroup.LayoutParams.
Layoutparams is equivalent to a layout Information package that encapsulates the location, height, and width of the layout . Suppose an area on the screen is occupied by a layout, and if you add a View to a layout , it's best to tell layout of the user's expectations, that is, a recognized layoutparams Pass in.
can describe layoutparams, on the chess board, each piece occupies a position, that is, each piece has a position of information, such as this pawn in 4 row 4 column, where "4 rows and 4 Columns" is the layoutparams of a pawn .
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.
/** * How to get the screen*/ Private voidmywindowwidth () {//get the width of the screenWindowManager wm = (WindowManager) homeactivity. This. Getsystemservice (Context.window_service); //Get the default display screen width intwidth = Wm.getdefaultdisplay (). GetWidth ();//Remove the width of the screen//gets the parameter properties of the screen to the left of the layoutLinearlayout.layoutparams LP =(Layoutparams) left_menu. Getlayoutparams (); //Set the left screen width property to the default screen width of 8/10Lp.width = width/Ten*8; //set the Position property of the left screen to the -8/10 of the left marginLp.leftmargin =-width/Ten*8; //put the parameter properties on the left side of the layout to the menu barLEFT_MENU.SETLAYOUTPARAMS (LP); //get the parameter properties of the ViewGroup screenViewgroup.layoutparams LP2 =(Layoutparams) viewgroup.getlayoutparams (); //Set the screen width of the viewgroup to the default widthLp2.width =width; //put the parameter properties of the set right ViewGroup screen on a custom layoutViewgroup.setlayoutparams (LP2); //get parameter properties for Titile in the screenLP3 =(Layoutparams) title.getlayoutparams (); //set the width of the titile to the default width of the screenLp3.width =width; }
Add view to ViewGroup
Viewgroup.addview (localactivitymanager.getactivity (activityname) new layoutparams ( layoutparams.fill_parent, layoutparams.fill_parent));