gpt4 book ai didi

android - 阴影层适用于模拟器,但不适用于实际设备

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:20:17 24 4
gpt4 key购买 nike

我正在创建一个自定义可绘制对象(它从可绘制对象扩展而来),我正在尝试为其添加阴影效果。

这是我的部分代码:

public void draw(Canvas canvas) {
Path path = new Path();
path.moveTo(0, 0);
path.lineTo(0, Y/2);
path.lineTo(X/2, Y);
path.lineTo(X, Y/2);
path.lineTo(X, 0);
path.lineTo(0, 0);
Paint paint = new Paint();
paint.setColor(context.getResources().getColor(R.color.red_dark));
paint.setStyle(Style.FILL_AND_STROKE);
paint.setStrokeWidth(2f);
paint.setShadowLayer(1, 0, 10f, context.getResources().getColor(R.color.black));
canvas.drawPath(path, paint);
}

我不知道为什么,但它放了一个相同颜色的阴影,我仔细检查了所有内容,但我看不出问题出在哪里。我在 galaxy nexus 上测试它。但在模拟器上它工作得很好。

最佳答案

我不确定,但这可能是因为硬件加速。如果 View 加速,setShadowLayer 将不起作用。尝试禁用整个应用程序的加速并检查。 Read this.

Unsupported Drawing Operations

setShadowLayer(): works with text only

Use a software layer type to force a view to be rendered in software. If a view that is hardware accelerated (for instance, if your whole application is hardware acclerated), is having rendering problems, this is an easy way to work around limitations of the hardware rendering pipeline.

使用setLayerType将层类型设置为单个 View 或 turn off acceleration in your manifest对于整个应用程序。

关于android - 阴影层适用于模拟器,但不适用于实际设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15341247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com