最近在做一个电子书项目,想要把开源的Shelves+iReader的翻页卷曲等弄到一起,在做卷曲效果时遇到以下问题:
java.lang.unsupported operation exception, android.view.GLES20Canvas.clipPath(GLES20Canvas...
万能的谷哥告诉我,这是硬件加速的问题,可是我从来没开启过硬件加速啊,做了个测试,View层的硬件加速已经干掉了
,那硬件加速肯定来自于Canvas绘制层了,测试了下,果然是绘制层开启了硬件加速。
给一个链接,讲硬件加速讲的很清楚的文章:点击查看
综合看了之后解决了,即在AndroidManifest.xml application下设定:
<application android:label="@string/application_name" android:hardwareAccelerated="false">
--------------------------------------------------------------------------------------------------------------------------------------------------
关于 Hardware Acceleration
1、不同层级的加速:
Application
<applicationandroid:hardwareAccelerated="true" ...>
Activity
<application
android:hardwareAccelerated="true">
<activity ...
/> <activity
android:hardwareAccelerated="false"
/> </application>
Window
getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
View
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
2、如何判断是否开启了硬件加速
在绘制之前,你必须做该测试 Canvas.isHardwareAccelerated() 替代View.isHardwareAccelerated() 在必要时。
View.isHardwareAccelerated() ;//returns true if the View is attached to a hardware accelerated window. Canvas.isHardwareAccelerated();//
returns true if the Canvas is hardware accelerated
3、开启硬件加速之后,许多2D的绘制方法会抛出异常:
Canvas clipPath() clipRegion() drawPicture() drawTextOnPath() drawVertices() Paint setLinearText() setMaskFilter() setRasterizer() Xfermodes AvoidXfermode PixelXorXfermode
In addition, some operations behave differently with hardware acceleration enabled:
Canvas clipRect(): XOR, Difference and ReverseDifference clip modes are ignored. 3D transforms do not apply to the clip rectangle drawBitmapMesh(): colors array is ignored Paint setDither(): ignored setFilterBitmap(): filtering is always on setShadowLayer():
works with text only PorterDuffXfermode PorterDuff.Mode.DARKEN will be equivalent to SRC_OVER when blending against the framebuffer. PorterDuff.Mode.LIGHTEN will be equivalent to SRC_OVER when blending against
the framebuffer. PorterDuff.Mode.OVERLAY will be equivalent to SRC_OVER when blending against the framebuffer. ComposeShader ComposeShader can only contain shaders of different types (a BitmapShader and a LinearGradient for instance, but not two instances
of BitmapShader ) ComposeShader cannot contain a ComposeShader