Reprint Please specify source: http://blog.csdn.net/devilnov/article/details/44835243
Import Android.content.pm.activityinfo;import Android.view.display;import Android.view.gravity;import Android.view.window;import Android.view.windowmanager;import android.view.windowmanager.layoutparams;/** * Dynamic Adaptation * The screen is scaled proportionally * @author Administrator * */public class Uiscaleutil {/** * Pad Edition Zoom * W Long Edge * H Short edge */public final static double Pad_scale_longger = 0.9;public final static double Pad_scale_long = 0.8;public final static double pad_scale_short = 0.6; /** * Dynamic Scaling of Dialog w * @param window * @param orientation */public static void scaledialog (window window, int orientati On) {WindowManager m = Window.getwindowmanager ();D isplay d = m.getdefaultdisplay ();//Get screen width, High with windowmanager.layoutparams p = window.getattributes (); Gets the current parameter value of the dialog box double Scalew = 1;if (Orientation = = Activityinfo.screen_orientation_landscape) {Scalew = Uiscaleutil.pad_ Scale_short;} else {scalew = Uiscaleutil.pad_scale_long;} int framewidth = (int) (D.getwidth () * Scalew); if (Framewidth <) {framewidth = (int)(D.getwidth () * Uiscaleutil.pad_scale_longger);} P.width = (int) (FRAMEWIDTH/2); The width is set to half of the screen scale, which is half window.setattributes (p) of the width of the checkout; window.setgravity (Gravity.center); /** * Dynamically scales the activity's W and H * @param window * @param orientation */public static void scaleactivity (window window, int o rientation) {WindowManager m = Window.getwindowmanager (); Display d = m.getdefaultdisplay (); To get the screen width, high layoutparams p = window.getattributes (); Gets the current parameter value of the dialog box double Scaleh = 1; Double Scalew = 1; if (orientation = = Activityinfo.screen_orientation_landscape) {Scaleh = Uiscaleutil.pad_scale_long; Scalew = Uiscaleutil.pad_scale_short; }else{Scaleh = Uiscaleutil.pad_scale_short; Scalew = Uiscaleutil.pad_scale_long; } p.height = (int) (D.getheight () * Scaleh); The height is set to the ratio of the actual screen width p.width = (int) (D.getwidth () * Scalew); The width is set to the ratio of the actual screen width if (d.getheight () > D.getwidth ()) {if (P.widTh <) {p.width = (int) (D.getwidth () * Uiscaleutil.pad_scale_longger); }}else if (D.getheight () < D.getwidth ()) {if (P.height <) {p.height = (int) (d.getheight () * Uiscaleutil.pad_scale_longger); }} p.alpha = 1.0f; Set itself transparency P.dimamount = 0.0f; Set the Dark degree window.setattributes (p); Setting effective window.setgravity (Gravity.center); Set Align Right}}
Android pad Dynamic Adaptation scheme