package com.example.androidtest; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Display; import android.view.WindowManager; public class OrientationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_orientation); //判断屏幕方向 WindowManager wm = getWindowManager(); Display d = wm.getDefaultDisplay(); if(d.getWidth() > d.getHeight()){ Log.d("Orientation", "Landscape mode"); }else{ Log.d("Orientation", "Portrait mode"); } } }