gpt4 book ai didi

java - 使用 Display.getRotation() 进行屏幕旋转

转载 作者:搜寻专家 更新时间:2023-11-01 09:15:51 25 4
gpt4 key购买 nike

我正在努力让我的应用永远不会进入纵向模式,但能够在 2 个横向屏幕 View 之间切换。我知道这可以在 Gingerbread (2.3) 中轻松完成,但我无法为其他版本的 android 手动执行此操作,我的代码如下:

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();
if (orientation == 1) {
/* The device is rotated to the left. */
Log.v("Left", "Rotated Left");
} else if (orientation == 3) {
/* The device is rotated to the right. */
Log.v("Right", "Rotated Right");
} else {

}

我的问题是如何根据检测到的旋转翻转屏幕 View 的 x 轴和 y 轴?我如何掌握它们以扭转它们?

最佳答案

据我所知2.3之前是不支持倒排的。因此,除非您使用自定义 SurfaceView 绘制屏幕,​​否则我会说您不能使用标准小部件来完成。使用表面 View ,您只需在渲染之前转换整个 Canvas 。

此外,您应该使用常量来了解当前方向(没有魔数(Magic Number)),请参阅 Configuration class API documentation

if (orientation==Configuration.ORIENTATION_LANDSCAPE) 

关于java - 使用 Display.getRotation() 进行屏幕旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4757632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com