Android:根据屏幕尺寸改变方向

发布于 2025-01-06 00:34:57 字数 198 浏览 1 评论 0原文

如果屏幕足够大,我需要我的某些活动才能更改为横向。

这意味着屏幕尺寸为 5.1 英寸以上的平板电脑和手机。

无论如何,是否可以通过重写 onConfigurationChanged(...) 并使用 XML 语句来做到这一点:

android:configChanges="orientation"

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2025-01-13 00:34:57

你当然可以。您可以嗅探屏幕尺寸,并使用 if 语句 if 二进制或开关来手动设置视图的方向:

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

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文