Android的TextureView和硬件加速硬件加速、Android、TextureView

2023-09-05 02:18:35 作者:钟爱一生

我想实现在此页面所示的例子。我已经尝试了三种不同的设备上运行的Andr​​oid 4.0及以上,且在任何情况下,我得到一个黑色的屏幕,这样的警告:

I am trying to implement the example shown on this page. I have tried on three different devices running android 4 and above, and in all cases I get a black screen with this warning:

01-27 20:01:22.683: W/TextureView(4728): A TextureView or a subclass can only be used with hardware acceleration enabled.

我启用了硬件加速的应用程序清单:

I have turned on hardware acceleration in the application manifest:

<application
    android:hardwareAccelerated="true"
    [etc...]

但接下来的检查我的自定义视图的onAttachedToWindow方法始终返回false

But the following check my custom view's onAttachedToWindow method always returns false

private class MyTextureView extends TextureView
{
    public MyTextureView(Context context) {
        super(context);
    }

    @Override
    protected void onAttachedToWindow()
    {
        super.onAttachedToWindow();
        Log.d("", Boolean.toString(mTextureView.isHardwareAccelerated()));          
    }
}

有谁知道什么是错在这里?

Does anyone know what is wrong here?

感谢

推荐答案

如果您测试与仿真器,那么请检查配置硬件加速。 请检查此线程的详细信息: http://developer.android.com/tool​​s/devices/emulator.html#acceleration

If you testing with Emulator then please check configuration for hardware acceleration. Please check this thread for more info: http://developer.android.com/tools/devices/emulator.html#acceleration