获取手机分辨率(屏幕大小)

最近老是忘记手机的分辨率,然后一直上百度云找,,,,,今天直接上一篇博客,免得老那么麻烦

 private DisplayMetrics displayMetrics;
    int height;
    int width;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        displayMetrics=new DisplayMetrics();

        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
height=displayMetrics.heightPixels;
        width=displayMetrics.widthPixels;

    waitingView=new WaitingView(MainActivity.this);
setContentView(waitingView);
        Toast.makeText(MainActivity.this,""+height,Toast.LENGTH_SHORT).show();

    }

就这样,搞定

你可能感兴趣的:(android,Android)