安卓:根据屏幕大小取向变化 [英] Android: Orientation Change Based On Screen Size
本文介绍了安卓:根据屏幕大小取向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要我的某些活动,如果屏幕够大只更改为横向。
这意味着平板电脑和手机与屏幕尺寸5.1in +
反正是有通过覆盖onConfigurationChanged(...),并使用XML语句来做到这一点:
的android:configChanges =方向
解决方案
您当然可以。您可以嗅出了屏幕尺寸和if语句,如果二进制或开关,否则手动设置视图的方向使用:
显示D =((窗口管理器)getSystemService(Context.WINDOW_SERVICE))getDefaultDisplay()。
屏幕宽度=(int)的(d.getWidth());
screenHeight =(int)的(d.getHeight());setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
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"
解决方案
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);
这篇关于安卓:根据屏幕大小取向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文