View.isHardwareAccelerated()始终是假的 [英] View.isHardwareAccelerated() is always false

查看:1226
本文介绍了View.isHardwareAccelerated()始终是假的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种观点认为是硬件上的很多设备加速。在该视图我需要能够检查硬件加速是否被使用。 根据Android的SDK文档,这是用做 View.isHardwareAccelerated()。有趣的是,在支持硬件加速设备进行测试时,此方法始终返回false,即使意见本身实际上正在硬件加速。 (我已经得出结论验证了这一点)它变得更加混乱:

I've got a View that is hardware accelerated on many devices. Within that View I need to be able to check whether hardware acceleration is used. According to Android SDK documentation, this is done using View.isHardwareAccelerated(). The interesting thing is that when testing on devices that support hardware acceleration, this method always returns false, even though the Views themselves actually are being hardware accelerated. (I've conclusively verified this) It gets more confusing:

如果我打电话到 View.getLayerType()我看到它总是被设置为 View.LAYER_TYPE_NONE 。如果我做调用 View.setLayerType(View.LAYER_TYPE_SOFTWARE)我可以有效地禁用硬件加速。通过调用 View.setLayerType(View.LAYER_TYPE_HARDWARE) View.setLayerType(View.LAYER_TYPE_NONE)。为什么会 View.LAYER_TYPE_NONE 启用硬件加速???

If I make a call to View.getLayerType() I see that it is always set to View.LAYER_TYPE_NONE. If I make call to View.setLayerType(View.LAYER_TYPE_SOFTWARE) I can effectively disable hardware acceleration. I can re-enable it by calling either View.setLayerType(View.LAYER_TYPE_HARDWARE) OR View.setLayerType(View.LAYER_TYPE_NONE). Why would View.LAYER_TYPE_NONE enable hardware acceleration???

继续,对于在不支持硬件加速,好像我只是可以通过检查检查状态是否 View.LAYER_TYPE_SOFTWARE 设置,但是我有我的怀疑设备该方法在不支持硬件加速装置不会工作。我想知道我是否滥用 View.isHardwareAccelerated()或者如果它只是坏了。

Moving on, for devices that do support hw acceleration it seems like I can just check status by checking whether or not View.LAYER_TYPE_SOFTWARE is set, however I have my suspicions that this method wont work on devices that do not support hw acceleration. I'd like to know whether I am misusing View.isHardwareAccelerated() or if it's simply broken.

编辑: 我觉得我有点更进一步地理解这个问题。这个问题也是有帮助的:

I think I'm a little closer to understanding the problem. This question was also helpful:

<一个href="http://stackoverflow.com/questions/6792115/detect-hardware-acceleration-at-runtime-android">Detect硬件加速运行:安卓

我的工作原理是,查看犯规还不知道无论是硬件加速与否时,它的构造函数被调用,这就是我做我的支票。如果是这样的话,我想知道我可以在我的课扩展视图,让我成功地检查硬件加速覆盖。我怀疑 View.onSizeChanged(...)会的工作,但我想,以避免使用的东西,可能会被称为多次。

My working theory is that the View doesnt yet know whether it's hardware accelerated or not when it's constructor is called, which is where I am doing my check. If this is the case, I'm wondering what I can override in my class that extends View that will allow me to successfully check hardware acceleration. I suspect that View.onSizeChanged(...) would work, but I'd like to avoid using something that can potentially be called numerous times.

编辑#2: 看起来就是这样。我把我的支票到 View.onSizeChanged(),它现在报告正确。我还在想,如果那里有我在查看一个更好的地方,我可以尽管提出这项检查。

EDIT #2: Looks like that was it. I moved my check into View.onSizeChanged() and it now reports correctly. I'm still wondering if theres a better place within my View that I can move this check though.

推荐答案

由于戴安娜Hackborn提到了这个帖子:的 https://groups.google.com/forum/#​​!topic/android-developers/vAH0HAZg0uU

As Diane Hackborn mentions in this post: https://groups.google.com/forum/#!topic/android-developers/vAH0HAZg0uU

您应该检查isHardwareAccelerated()后视图被贴在窗户上 - 例如,在onAttachedToWindow()!

You should check isHardwareAccelerated() after the view was attached to the window - e.g. in onAttachedToWindow()!

这篇关于View.isHardwareAccelerated()始终是假的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆