Android: Orientation Change Based On Screen Size

只愿长相守 提交于 2019-12-11 05:24:13

问题


I need certain activities of mine to only change to landscape if the screen is big enough.

This means tablets and phones with screen size 5.1in+.

Is there anyway to do this through overriding onConfigurationChanged(...) and using the XML statement:

android:configChanges="orientation"

回答1:


You certainly can. You can sniff for the screen size and using an if statement if binary or a switch otherwise to set the orientation of the view manually:

Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();         
screenWidth = (int)(d.getWidth());
screenHeight = (int)(d.getHeight());

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


来源:https://stackoverflow.com/questions/9320559/android-orientation-change-based-on-screen-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!