判断屏幕方向

作者:追风剑情 发布于:2015-7-22 22:03 分类:Android

  1. package com.example.androidtest;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.Display;
  7. import android.view.WindowManager;
  8.  
  9. public class OrientationActivity extends Activity {
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_orientation);
  15. //判断屏幕方向
  16. WindowManager wm = getWindowManager();
  17. Display d = wm.getDefaultDisplay();
  18. if(d.getWidth() > d.getHeight()){
  19. Log.d("Orientation", "Landscape mode");
  20. }else{
  21. Log.d("Orientation", "Portrait mode");
  22. }
  23. }
  24. }

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号