方向变化与硬件加速设置混淆
我正在使用 sdk 11 (Honeycomb) 开发一个应用程序。在这个应用程序中,我利用硬件加速(在应用程序级别)来使动画更流畅,如果没有它,它们就会慢得令人无法接受。由于我的客户确实想要拥有它们,因此我必须找到另一种解决方案,而不是关闭加速。
问题本身是我有一个 Activity
,其中包含很少的 WebView
元素。 3,确切地说 - 1 始终显示,另外 2 个用于预加载页面,因此它们是不可见的(我的意思是位于屏幕之外,但仍然“可见”)。我使用翻译动画在它们之间“切换”。打开硬件加速后,它们会错误地渲染网页 - 我在页面上看到大而闪烁的黑框。这当然是不可接受的,所以我通过关闭所有WebView的硬件加速来绕过这个问题:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
我也尝试在xml文件中设置它(android:layerType="software"
),但是它工作方式完全相同(应该如此)。无论如何,这两种方法都工作得很好 - 动画和 WebView 足够平滑,并且没有任何瑕疵。然而,一旦方向改变,问题就会出现。尽管我在代码中没有对纵向和横向模式进行重要区分,但它的工作原理如下:
- Activity 以纵向模式启动,将方向更改为横向,返回纵向,依此类推。一切都按预期进行。
- 活动以横向模式开始。效果很好。方向更改为纵向。文物再次开始显现。大多数情况下,当我滚动/缩放页面时,整个屏幕都会变黑,网页会千载难逢地显示出来。这与 WebView 使用硬件加速完全相同。回到横向——它再次正常工作。
这让我认为硬件加速可能是问题所在。通过尝试在视图层次结构的不同级别设置软件加速,看看这种奇怪的行为是否停止,我证明了自己的正确性。我发现它确实停止了,并且它的工作没有错误,但只有当整个活动被软件加速时,这对我来说是不可接受的(我的翻译动画![+网络视图中的缓慢滚动])。如果只有布局 xml 文件中的视图/视图组设置为软件加速,它仍然会出现错误。方向变化是否会引发此类行为?任何解决方案、黑客、提示、建议、想法、想法,无论多么不完整,都是受欢迎的——我不接受这些。
如果您需要更多信息或一些代码,我很乐意提供给您。
谢谢您的宝贵时间!
I'm developing an app with sdk 11 (Honeycomb). In this app I make use of hardware acceleration (at application level) to make animations smoother and without it, they are unacceptably sluggish. Since my client really wants to have them, I have to find another solution than turning the acceleration off.
The problem itself is that I have an Activity
which contains few WebView
elements. 3, to be exact - 1 is always shown and 2 others are used for preloading pages, so they are invisible (I mean positioned off the screen, but still "visible"). I use translation animation to "switch" between them. With hardware acceleration on, they render web pages incorrectly - I get big, flickering black boxes over the page. This is of course unacceptable, so I bypassed the problem by turning hardware acceleration off for all WebViews:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
I've also tried to set this in xml file (android:layerType="software"
), but it worked exactly the same way (as it should be). Anyway, both those methods work pretty well - the animations and WebViews are smooth enough and there are no artifacts. The problem arises however once the orientation changes. Even though I make no important distinctions between portrait and landscape mode in my code, it works like this:
- Activity starts in portrait mode, change orientation to landscape, back to portrait, and so on. Everything works as expected.
- Activity starts in landscape mode. It works fine. Orientation changes to portrait. Artifacts start to show again. Most often whole screen just goes black with webpage showing through once in the blue moon when I scroll/zoom the page. This is exactly the same as if the WebViews used hardware acceleration. Back to landscape - it works fine again.
This had led me to think that the hardware acceleration might be the problem. I was proved myself right by trying to set software acceleration at different levels of view hierarchy to see if this strange behavior stops. I found out that it does indeed stop, and it works without bugs, but only once whole Activity is software accelerated, which is unacceptable to me (my translation animations! [+slow scrolling in webviews]). If only views/viewgroups in the layout xml file are set to be software accelerated, it still bugs. Is there anything about orientation changes which can trigger such behavior? Any solutions, hacks, hints, suggestions, ideas, thoughts, however incomplete, are welcome - I'm out of those.
If you need more info or some code, I will gladly provide it to you.
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论