Recently, you need to specify the size and location of the imageview in the code when you are working on a project. After a day of research, you can finally share it with us.
Hope to help you
The following uses imagview as an example:
// Obtain control layout Parameters
Layoutparams Param = (layoutparams) imageview. getlayoutparams ();
// Dynamically specify the widget size and position
Param. leftmargin = 20;
Param. topmargin = 20;
Param. rightmargin = 100;
Param. bottommargin = 100;
Param. width = 50;
Param. Height = 30;
// You can also specify the location, but this is not flexible.
Params. setmargins (100,100,100,100 );
Obtain the widget location:
Imageview t = (imageview) findviewbyid (R. Id. L );
Log. E ("MSG", left: "+ T. getleft () + "Right:" + T. getright () + "Top:" + T. gettop () + "bottom:" + T. getbottom ());
Note! If the parameters output in the oncreate () event of the activity are all 0, these parameters can be obtained only after the UI control is fully loaded.