Issue with ComposeShader on Android 4.1.1

后端 未结 1 598
庸人自扰
庸人自扰 2021-01-01 19:52

I\'m just trying to implement a color picker for my android application, and ran into a strange issue on Android 4.1.1. The following code does not create the expected gradi

相关标签:
1条回答
  • 2021-01-01 20:35

    Found the problem: Seems that it has to do with the hardware acceleration. As described here 'ComposeShader can only contain shaders of different types (a BitmapShader and a LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling setLayerType(View.LAYER_TYPE_SOFTWARE, null).'

    I saw, that this method is available since SDK 11. My App supports all versions starting with SDK 7, so I have to check if the method is available:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    

    Now everything's fine.

    0 讨论(0)
提交回复
热议问题