android获取屏幕长宽的方法

package com.kale.imageview02;

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); }
}
上一篇:ASP.NET Core快速入门--学习笔记系列文章索引目录


下一篇:hdoj 1176(可转化为数塔)