如何保持屏幕在Android的横向模式横向、屏幕、模式、Android

2023-09-06 00:08:28 作者:阳光下的白鸽

我应该始终显示在横向模式下的活动。所以我加了安卓screenOrientation =风景。但问题是,当我180度旋转设备中,显示被反转。有没有办法来处理这​​个问题,让画面元素总是正确的显示?

解决方案

因此​​,只要每个人的信息,这就是我所做的。

在Android清单添加机器人:screenOrientation =景观 在简历上添加方法的code这些行

 显示显示=((窗口管理器)getSystemService(WINDOW_SERVICE))getDefaultDisplay()。
INT方向= display.getRotation();

如果(定向== Surface.ROTATION_180)
{
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
 

这样我的屏幕上始终被定位正确,即使用户拥有该设备倒挂。

I have an activity which should always be displayed in Landscape mode. So i added android:screenOrientation="landscape". But the problem is when i rotate the device by 180 degrees, the display is inverted. is there a way to handle this issue so that the screen elements are always shown correctly.?

解决方案 2021 08 12 Android APP 保持屏幕常亮和取消屏幕常亮方法

So just for everyone information, this is what i did.

In Android manifest added android:screenOrientation="landscape". In on resume method add these lines of code

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();

if(orientation==Surface.ROTATION_180)
{
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}

This way my screen is always positioned correctly even if user holds the device upside down.