简体   繁体   English

在设备旋转Android上查看横向活动时出现黑屏

[英]Black screen when opining landscape activity on device rotation android

Hey I have android app which is always in portrait mode 嘿,我有始终处于人像模式的android应用
except one activity which is in landscape mode 除了一项横向活动

and the way to open this activity is to rotate my device to landscape mode 而打开此活动的方法是将设备旋转到横向模式
and I achieve this using background service with SensorEventListener 我使用SensorEventListener的后台服务来实现
but there are many problems I faced first one is the returned value from the SensorEvent are difference between devices 但是我遇到的许多问题首先是SensorEvent的返回值是设备之间的差异

the second issue is that sometimes when I rotate my device for long period by wrong the device screen rotated for few second with black screen before loading the landscape view 第二个问题是,有时当我因错误长时间旋转设备时,设备屏幕在加载横向视图之前与黑屏一起旋转了几秒钟

I'm using the code in this library for handling orientation rotation sensor code 我正在使用此库中的代码来处理方向旋转传感器代码

is the any better way to achieve this ,and what is the cause of black screen issue thanks 是实现这一目标的更好方法,黑屏问题的原因是什么?谢谢

You don't need to use the sensors to detect device rotation - the system already does this for you. 您无需使用传感器来检测设备的旋转-系统已经为您完成了此操作。

Simply provide a different layout resource file in the res/layout-land folder. 只需在res / layout-land文件夹中提供其他布局资源文件。 As long as you haven't done anything to force portrait-only, Android will destroy your Activity and recreate it with the new layout when the device is rotated. 只要您还没有执行任何强制仅肖像的操作,Android就会销毁您的Activity并在旋转设备时以新的布局重新创建它。

The key to not having the momentary flash of 'black screen' is making sure that you don't do anything time-consuming in onCreate or onCreateView. 暂时不出现“黑屏”现象的关键是确保您在onCreate或onCreateView中不做任何耗时的操作。

Make sure that you do long-running (more than a couple of hundred milliseconds) on a background thread, and never do any network access on the UI thread. 确保在后台线程上长时间运行(超过几百毫秒),并且绝对不要在UI线程上进行任何网络访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当设备处于纵向=屏幕上的可见旋转时,平板电脑上的锁定横向方向+活动开始 - Locked landscape orientation on tablet + activity started when device in portrait = visible rotation on screen Android:活动中的屏幕旋转不会切换纵向/横向布局 - Android: Screen Rotation within Activity doesnt switch portrait/landscape layout Android:活动恢复时黑屏闪烁 - Android: Black screen flashes when activity resumes Android:开始新活动时出现黑屏 - Android: Black screen when starting a new activity 启用设备屏幕旋转横向或纵向,仅适用于平板设备 by Flutter - Enable Device Screen Rotation Landscape or Potrait, only for Tablet Device by Flutter Android:活动之间的黑屏 - Android: Black Screen between Activity android黑屏设备测试 - android black screen on device test 在Android应用中更改活动时,屏幕变黑 - Screen goes black when changing activity in Android app 如何在切换活动时删除黑屏(不起作用)-在Android上 - how to remove black screen when switching activity( is not working) - on android 在 Android 中返回视频播放活动时黑屏 - Black screen when returning to video playback activity in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM