Android中获取屏幕长宽的方法

package com.kale.screen;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;

public class MainActivity extends Activity {

    @SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        int dw = getWindowManager().getDefaultDisplay().getWidth();//获得手机屏幕的宽度
        int dh = getWindowManager().getDefaultDisplay().getHeight();//获得手机屏幕的高度
        

        Log.i("h", "height:"+dw);
        Log.i("w", "width:"+dh);
        
        //推荐的获取屏幕长宽的方式,但需要API13
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int windowHeight = size.y;
        int windowWidth = size.x;
        
        Log.i("w","width:"+ windowWidth);
        Log.i("h", "height:"+ windowHeight);
        
    }
}

 

Android中获取屏幕长宽的方法,布布扣,bubuko.com

Android中获取屏幕长宽的方法

上一篇:PM2 部署 nodejs API项目


下一篇:opencv 环境配置-windowsx64 +VS2017