美文网首页
Android获取并设置手机窗口大小getScreenSize(

Android获取并设置手机窗口大小getScreenSize(

作者: CodeChenL | 来源:发表于2017-07-21 11:10 被阅读0次
    public static intSCREEN_WIDTH= -1;
    public static intSCREEN_HEIGHT= -1;
    public static floatDIMEN_RATE= -1.0F;
    public static intDIMEN_DPI= -1;
    
    
    public void getScreenSize() {
    
    WindowManager  windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
    
    DisplayMetrics dm = new DisplayMetrics();
    
    Displaydisplay = windowManager.getDefaultDisplay();
    
    display.getMetrics(dm);
    
    DIMEN_RATE= dm.density/1.0F;
    
    DIMEN_DPI= dm.densityDpi;
    
    SCREEN_WIDTH= dm.widthPixels;
    
    SCREEN_HEIGHT= dm.heightPixels;
    
    if(SCREEN_WIDTH>SCREEN_HEIGHT) {
    
    int t =SCREEN_HEIGHT;
    
    SCREEN_HEIGHT=SCREEN_WIDTH;
    
    SCREEN_WIDTH= t;
    
    }
    
    }
    

    相关文章

      网友评论

          本文标题:Android获取并设置手机窗口大小getScreenSize(

          本文链接:https://www.haomeiwen.com/subject/qnwskxtx.html