- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在 hardware accelerated 自定义 View
添加到 ScrollView
或 ListView
以下两个代码 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
}
相同的结果:
但是对于后面的代码 fragment ,只要你滚动 ScrollView
(我在下面有不可见的虚拟 View
所以我可以滚动) 和helloworld 触摸 ActionBar
,发生了一些非常有趣的事情,你看到了 intelligent humankind used to see in old Windows OS 的东西.
我知道硬件加速模式不支持 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/
我正在使用以下代码制作一个转轮。 @Override public void onDraw(Canvas canvas) { super.onDraw(canvas);
在 hardware accelerated 自定义 View 添加到 ScrollView 或 ListView 以下两个代码 fragment 产生相同的结果: (请暂时忽略最佳实践) @Over
我在下面有以下代码。 public class CompassActivity extends Activity { public class OuterCircle extends View
我正在尝试创建一个自定义 View ,它有一个矩形,并且在它的正上方和正下方有一些文本。到目前为止,我使用 drawTextOnPath 方法成功地在绘制的矩形上方获取文本。然而,应该在矩形下方的那个
我正在尝试使用图像和文本绘制自定义 View ,一切正常,只是我的文本应该从左到右开始,但它是从右到左倒置的。 我在这幅画中使用了路径,矩形 我的XML输入如下, with xml input as
我有一个函数可以使用 drawTextOnPath 在 Canvas 上绘制文本。我计算偏移量一切正常,但我想以特定方式绘制它。当前文本旋转偏移等于圆圈偏移。我想将文本旋转 90/45 度。但我想不通
canvas.DrawTextOnPath 似乎不适用于 Lollipop 设备。看看这里的区别。 (连结 10图片正确,但 Lollipop 显示不正确) 代码是一个简单的路径绘制。 // Path
我正在使用 drawTextOnPath() 在 Canvas 上显示一些文本,我需要知道所绘制文本的尺寸。我知道这对于由多条线段、曲线等组成的路径是不可行的,但我的路径是一条完全水平的线段。我正在使
我是 Android 新手,我编写了以下示例代码。 public class Circle extends View { Paint paint = new Paint(); Path
我在扩展 View 中设置了一些代码,这些代码设置了一些易于缩放的图形(类似于矢量)。 (我的比例设置为 0-1.0) 我注意到,当我将油漆填充设置为 FILL 时,路径上绘制的文本看起来是正确的,但
我正在使用我自己的 https://github.com/mdg-iitr/RotatingText 版本为了显示一个旋转的文本小部件。此 GitHub 中提供了一个视频,可让您查看动画。这个想法是设
我是一名优秀的程序员,十分优秀!