gpt4 book ai didi

android - `drawTextOnPath()` 硬件加速的奇怪行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:05:33 26 4
gpt4 key购买 nike

hardware accelerated 自定义 View 添加到 ScrollViewListView 以下两个代码 fragment 产生相同的结果: (请暂时忽略最佳实践)

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// centering stuff
float centerX = getWidth() / 2f;
float centerY = getHeight() / 2f;
float size = 80;
float halfSize = size / 2f;
float left = centerX - halfSize;
float top = centerY - halfSize;

RectF oval = new RectF(left, top, left + size, top + size);

Path path = new Path();
path.addArc(oval, 160, 359);

Paint paint = new Paint();
paint.setTextSize(30);
paint.setStyle(Style.STROKE);

canvas.drawTextOnPath("Hello world", path, 0, 0, paint); //<--- line A
canvas.drawCircle(centerX, centerY, 10, paint); //<--- line B
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// centering stuff
float centerX = getWidth() / 2f;
float centerY = getHeight() / 2f;
float size = 80;
float halfSize = size / 2f;
float left = centerX - halfSize;
float top = centerY - halfSize;

RectF oval = new RectF(left, top, left + size, top + size);

Path path = new Path();
path.addArc(oval, 160, 359);

Paint paint = new Paint();
paint.setTextSize(30);
paint.setStyle(Style.STROKE);

canvas.drawCircle(centerX, centerY, 10, paint); //<--- line B
canvas.drawTextOnPath("Hello world", path, 0, 0, paint); //<--- line A
}

相同的结果:

enter image description here


但是对于后面的代码 fragment ,只要你滚动 ScrollView (我在下面有不可见的虚拟 View 所以我可以滚动) 和helloworld 触摸 ActionBar,发生了一些非常有趣的事情,你看到了 intelligent humankind used to see in old Windows OS 的东西.

enter image description here


enter image description here

我知道硬件加速模式不支持 drawTextOnPath(),但为什么先调用它就可以工作?

最佳答案

drawTextOnPath() Android 4.1后支持硬件加速这在此处正式提到:https://code.google.com/p/android/issues/detail?id=37925但下一条评论似乎在某种程度上表明了你的问题,所以可能是一个错误。

当然,对于 4.1 之前的版本,只是不要让它使用 HW accel - 通过调用 View.setLayerType(View.LAYER_TYPE_SOFTWARE, null) 在您的 View 上设置软件层类型,并尝试权衡性能与错误

关于android - `drawTextOnPath()` 硬件加速的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761980/

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