判断屏幕方向

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

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");
		}
	}
}

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号