setShadowLayer Android的API差异 [英] setShadowLayer Android API differences

查看:1747
本文介绍了setShadowLayer Android的API差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的自定义视图组件为我的应用程序,我挣扎与添加阴影圆。

I develop a custom view component for my application and I am struggling with adding a shadow to a circle.

下面是我的扩展视图类的code

Here is the code of my class extending View

public class ChartView extends View {


    public ChartView(Context context, AttributeSet attributeSet){
        super(context, attributeSet);
        init();


    }
    Paint paint;
    public void init(){
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.WHITE);
        paint.setStyle(Paint.Style.FILL);
        paint.setShadowLayer(30, 0, 0, Color.RED);

    }
    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawCircle(getWidth()/2, getHeight()/2,50, paint);
    }
}

不过,我注意到,根据API,上有shadowLayer有很大的影响。

However, I noticed that depending on the API, There is a big impact on the shadowLayer.

下面是输出

<uses-sdk android:targetSdkVersion="13"/>

这里是与输出

<uses-sdk android:targetSdkVersion="14"/> //Higher target API yields the same output.

不知道如何克服这种不必要的行为?

Any idea how to overcome this unwanted behaviour ?

最好的问候

推荐答案

setShadowLayer()只支持文本时,硬件加速开启。硬件加速是在默认情况下,当 targetSdk = 14 或更高。一个简单的解决方法是把你查看一个软件层: myView.setLayerType(View.LAYER_TYPE_SOFTWARE,空)

setShadowLayer() is only supported on text when hardware acceleration is on. Hardware acceleration is on by default when targetSdk=14 or higher. An easy workaround is to put your View in a software layer: myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null).

这篇关于setShadowLayer Android的API差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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