(1) Get the size of the screen
WindowManager WindowManager = (windowmanager) getsystemservice (context.window_service);D isplay d = Windowmanager.getdefaultdisplay (); mwidth = D.getwidth (); mheight = D.getheight ();D isplaymetrics dm = getResources (). Getdisplaymetrics (); mscreendensity = dm.density;
(2) Dimensions of art design drawings
Uiwidth,uiheight
(3) Get zoom ratio
(4) The dimensions of all layouts are implemented in code
public static int getwidthsize (int size) {return (int) (size * scalewidth);} public static int gethightsize (int size) {return (int) (size * scaleheight);} public static float gettextsize (int pxsize) {return (pxsize*scaleheight)/mscreendensity;} public static void Setviewsize (int width, int height, View v) {int paramwidth = getwidthsize (width); int paramheight = gethightsize (height); Viewgroup.marginlayoutparams params = (viewgroup.marginlayoutparams) v.getlayoutparams (); if (width = INVALID) {params.width = Paramwidth; } if (height! = INVALID) {params.height = Paramheight; } v.setlayoutparams (params);} public static void setviewpadding (int left, int top, int. right, int. Bottom, View v) {left = Getwidthsize (left); top = gethightsize (top); right = Getwidthsize (right); Bottom = getwidthsize (bottom); V.setpadding (left, top, right, bottom);} public static void Setviewmargin (int left, int top, int. right, int bottom, View v) {int paramleft = Getwidthsize (left); int paramtop = gethightsize (top); int paramright = Getwidthsize (right); int parambottom = gethightsize (bottom); Viewgroup.marginlayoutparams params = (viewgroup.marginlayoutparams) v.getlayoutparams (); if (left! = INVALID) {params.leftmargin = Paramleft; } if (right! = INVALID) {params.rightmargin = Paramright; } if (top! = INVALID) {params.topmargin = Paramtop; } if (bottom! = INVALID) {params.bottommargin = Parambottom; } v.setlayoutparams (params);}