Android程序如何获得屏幕的方向和大小
1个回答
展开全部
public void onCreate() {
if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
Log.i("info", "landscape");
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Log.i("info", "portrait");}}
如果在androidmanifest.xml中加入配置
android:configChanges="orientation|keyboardHidden|navigation
当屏幕翻转时,Activity就不会重复的调用onCreate()、onPause()和onResume().
而是调用onConfigurationChanged(Configuration newConfig)
int screenWidth,screenHeight;
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
也有另一种方法:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询