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