Android - 打开和关闭屏幕时,覆盖在全屏视频最后一帧上的视图无法正确重绘
我有一个以纵向模式播放的视频。在视频的最后,我需要展示一些对其的看法。到目前为止效果很好。
然而,我遇到了一个问题,即在关闭屏幕、然后再次打开、然后解锁屏幕后返回活动时,视频最后一帧的视图无法正确重绘。
我观察到的是,当屏幕重新打开并解锁时。我的视频和图像首先在全屏模式之外渲染(状态栏仍然显示),然后屏幕将进入全屏模式,将所有视图向上移动并导致伪影。
看起来视图在渲染后通过转换到全屏而被移出其视图边界。
我真的很困惑如何防止这种情况发生。
这是 github 上的沙箱项目,以避免使这篇文章充满代码。
该项目的基本设置是这样的:
片段活动在其布局上有一个视频视图和一个按钮视图。 然后它将一个片段添加到 contentView 容器中。 contentView 在视频播放结束前 1 秒消失。
一切都很顺利,问题是在打开和关闭屏幕电源后返回到应用程序。
此外,有时视频会完全消失,将视图留在黑色背景上。
预先感谢您可以提供的任何帮助。
这是当您关闭、重新打开和解锁屏幕时发生的伪像。 请注意,我必须给它拍照。在 DDMS 上,屏幕截图工具可以正确查看图像。
I have a video that plays in portrait mode. At the end of the video, I need to display some views over it. This works fine so far.
I am however, having a problem where views that are over the last frame of a video don't redraw properly when coming back to the activity after turning the screen off, then on again, then unlocking the screen.
What i'm observing is that when the screen comes back on and I unlock. My video and images are first rendered outside of fullscreen mode (with the status bar still showing) then the screen will go into fullscreen mode shifting all of the views up and causing artifacting.
It seems like the views are being shifted out of their view bounds by the transition to fullscreen after they are rendered.
I'm really stumped as to how to prevent this from happening.
Here is the sandbox project on github to avoid making this a post full of code.
The basic setup for the project is this:
Fragment activity has a video view and a button view on it's layout.
It then adds a fragment into a contentView container. The contentView fades in 1 second prior to the end of video playback.
Everything works smoothly and the problem is with returning back to the app after powering the screen on and off.
Also, sometimes the video will just drop out entirely, leaving the views sitting atop a black background.
Thanks in advance for any help you can provide.
Here's the artifacting that happens when you turn the screen off, back on, and unlock.
Note that I had to take a picture of it. On DDMS the screenshot tool sees the images properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以选择在用户唤醒手机后解锁键盘保护时接收事件,而不是阻止屏幕关闭。
此时,调用 View 可能是个好主意.invalidate 在您的两个视图上,这应该会导致重绘。当锁定屏幕打开时,绘制链非常不稳定,因为您的应用程序在技术上是可见的,就在锁定屏幕下方。
rather than prevent the screen from turning off, you can opt in to receive an event when the user unlocks the keyguard after waking the phone.
At this point, it might be a good idea to call View.invalidate on both of your views, this should cause a redraw. The draw chain is very flaky while the lock screen is up, because your app is technically visible, just under the lock screen.
看起来覆盖布局已被控制器栏移动。
您不认为它受到控制器(播放/暂停/ff/rew + 进度)区域的影响吗?
It looks like the overlay layout was shifted by controller bar.
Don't you think it was affected by controller (play/pause/ff/rew + progress) area?
可能有一种方法可以防止屏幕首先关闭,因为这可以很好地解决您的重新绘制问题,希望这会有所帮助。
there may be a way to prevent the screen going off in 1st place as this would be good resolving your re draw issues, hope this helps.