Android pad Dynamic Adaptation scheme

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.